Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var projectile : Rigidbody;
  2. var projectileVelocity = 10;
  3. var BulletSound : GameObject;
  4. var WeaponReloadeSound : GameObject;
  5. var timeToDestroyBullet =3.0;
  6. var CanIShoot = 0;
  7. static var ammo = 3;
  8. static var clipForAmmo = 12;
  9. var timeToShoot = 0.3;
  10. var reloadedTime = 1;
  11.  
  12. function Update ()
  13. {
  14.     if (Input.GetButtonDown("Fire1"))
  15.     {
  16.         if(clipForAmmo > 0 && CanIShoot==0)
  17.         {
  18.                 CanIShoot = 1;
  19.                 var instantiateProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation);
  20.                 clipForAmmo -= 1;
  21.                 Invoke("ICanShoot", timeToShoot);
  22.         }
  23.    
  24.     }
  25.  
  26.     if (clipForAmmo == 0 && ammo>0)
  27.     {
  28.             if(Input.GetButtonDown ("Reload"))
  29.             {
  30.                 WeaponReloadeSound.audio.Play();
  31.                 Invoke("reloadWeapon", reloadedTime);
  32.             }
  33.     }
  34. }
  35.  
  36. function reloadWeapon ()
  37. {
  38.     clipForAmmo = 12;
  39.     ammo --;
  40. }
  41.  
  42. function ICanShoot ()
  43. {
  44.     CanIShoot = 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement