Advertisement
MaGuSware2012

Untitled

Dec 9th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. var BulletCount : int; //Ammount of bullets remaining in the clip
  2. var MagCapacity = 10; //The maximum capacity of bullets in the clip
  3. var MuzzleFlash : GameObject; //The muzzleFlash prefab
  4. var MuzzleFlashSpawn : GameObject; //The muzzleFlash spawn point object
  5. var BulletSpawn : GameObject; //The ejected bullet spawn point object
  6. var Bullet : GameObject; //The bullet prefab that gets ejected
  7. var BulletProj : GameObject; // Bullet will fire out of the barrel
  8. var BulletProjSpawn: GameObject; // spawn point form projectile
  9. var shootForce : int = -1500;
  10.  
  11. function Start()
  12. {
  13. animation["fire"].speed = 3; //set the firing animation to a little faster
  14. animation.wrapMode = WrapMode.Loop;
  15. animation.Play ("idle", PlayMode.StopAll);//start by playing the idle animation in loop
  16. }
  17.  
  18. function Update()
  19. {
  20. if (Input.GetButton ("Fire1") && animation.IsPlaying("idle") && BulletCount >= 1) //check to see if ready to fire
  21. {
  22. animation.wrapMode = WrapMode.Clamp; //using clamp allows the detection of the end of the animation to be more accurate
  23. animation.Play ("fire"); //play the firing animation
  24. }
  25. else if (Input.GetButton ("Fire1") && animation.IsPlaying("idle") && BulletCount <= 0) //if the bullets left in the clip is 0
  26. {
  27. animation.wrapMode = WrapMode.Clamp;
  28. animation.Play ("reload"); //reload the gun
  29. }
  30.  
  31. if (Input.GetKey(KeyCode.R) && animation.IsPlaying("idle") && BulletCount <30) //if ammunition is less than 30 you can reload
  32. {
  33. animation.wrapMode = WrapMode.Clamp;
  34. animation.Play ("reload"); //reload the gun
  35. }
  36. }
  37.  
  38. function Reload()
  39. {
  40. BulletCount = MagCapacity;//set the bullet count to = the maximum clip size
  41. }
  42.  
  43. function FireBullet() //Called via animation event to make the muzzle flash
  44. {
  45. MuzzleFlashSpawn.transform.Rotate(Vector3.up * Random.Range(0,360)); //set the spawn point to have a random rotation vector
  46. Instantiate(MuzzleFlash, MuzzleFlashSpawn.transform.position, MuzzleFlashSpawn.transform.rotation); //instantiate the muzzle flash
  47.  
  48. var BS = Instantiate(BulletProj, BulletProjSpawn.transform.position, BulletProjSpawn.transform.rotation);
  49. BS.rigidbody.AddForce(transform.forward * shootForce);
  50. }
  51.  
  52. function BackToIdle() //called via animation event at the end of fire/rotate in order to get back to idle
  53. {
  54. animation.wrapMode = WrapMode.Loop;
  55. animation.Play("idle");
  56. }
  57.  
  58. function EjectBullet() //Called via animation event to eject a bullet
  59. {
  60. Instantiate(Bullet, BulletSpawn.transform.position, BulletSpawn.transform.rotation);
  61. BulletCount = (BulletCount - 1); //when the bullet is ejected the bullet count reduces by one
  62. }
  63.  
  64. function SoundEffect(clip : AudioClip) //Called via animation event to make a sound effect
  65. {
  66. var randomPitch = (Random.Range(1.0,2.0));
  67. audio.pitch = randomPitch;
  68. audio.PlayOneShot(clip);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement