I need help with reloading my pistol. The problem I'm having is that on one time when the clip runs out, it runs fine. But then when I have to reload again the next time, it won't wait to do it, it will reload instantly. Sorry if this question has already been answered. Thanks for the help.
#pragma strict
var clip : int = 6;
var ammo : int = 42;
var pistol : GameObject;
function Update () {
if (Input.GetMouseButtonDown(0) && pistol.activeSelf && clip >= 1) {
clip -= 1;
}
if (clip == 0) {
Wait();
}
if (ammo < 0) {
ammo = 0;
}
}
function Wait () {
yield WaitForSeconds (3);
if (clip == 0 && ammo != 0) {
clip += 6;
ammo -= 6;
}
}
↧