- Home /
Question by
TheRichardGamer · May 31, 2013 at 05:41 AM ·
animationerrorgununknown
Unity does not recognize reload animation for gun
I am trying to make a reload script for my gun, so that when I hit 'R' my gun reloads, but the thing is that the animation and the reseting of current ammo doesn't work. What's the problem here?
var SMG : GameObject;
var smg_script : MonoScript;
var Ammo = 54;
var CurrentAmmo = 54;
var Wait : float;
function Update () {
if(Input.GetButtonDown("Fire1")){
CurrentAmmo -= 1;
if(CurrentAmmo == 0){
Reload();
}
else
if(Input.GetButtonDown("R")){
if(CurrentAmmo < 54){
Reload();
}
}
}
}
function Reload () {
SMG.animation.Play();
yield WaitForSeconds(Wait);
CurrentAmmo = 54;
}
Comment
Answer by Tarlius · May 31, 2013 at 05:45 AM
Your second if statement is nested in the first. It will be easier to see if you adjust your tabbing.
Your code looks like this at the moment.
if(button) {
if(ammo) {
} else if(button2) {
}
}
For the second button to be checked, you need to hold down the first one (which I assume is not what you're expecting)