x


gun wont reload

my gun wont reload right, here is my script:

 var projectile : Rigidbody;
 var canshoot = 1;
 var clone : Rigidbody;
 var reloading = 0;
 var ammo = 32;
 
 function Update () {
     if (Input.GetKey("space")) {
 if (canshoot == 1)    
         clone = Instantiate(projectile, transform.position, transform.rotation);
         clone.velocity = transform.TransformDirection (Vector3.left * 60);
         canshoot = 0;
         Invoke("CanShoot",0.1);
         ammo -= 1;
     }
     if (ammo == 0){
     reloading = 1;
     canshoot = 0;
     Invoke ("Reload",1);
    }
 }
 
 function CanShoot() {
 if (reloading == 0)
 canshoot = 1;
 }
 
 function Reload () {
 ammo = 32;
 reloading = 0;
 canshoot = 1;
 }

the gun shoots fine for the first clip, when it runs out of ammo it tries to reload and 1 second later when its reloaded it shoots every frame not every 0.1 seconds, what did i do wrong?

more ▼

asked Oct 19, 2011 at 10:51 PM

sam32x gravatar image

sam32x
183 161 130 132

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

found it, reload is called every frame.

more ▼

answered Oct 19, 2011 at 11:27 PM

sam32x gravatar image

sam32x
183 161 130 132

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x9411
x438
x56
x49
x45

asked: Oct 19, 2011 at 10:51 PM

Seen: 830 times

Last Updated: Oct 19, 2011 at 11:27 PM