Hello, i have an idle animation, an shooting animation, and a reload animation. But it’s really buggy! My Idle works great but when ever i try to shot or reload the gun just twitches (barely moves). Whats the problem here? Please help me!
~carlqwe
Code(javaScript):
#pragma strict
var ammo : int;
var cooldown : float;
function Start ()
{
GetComponent.<Animation>().Play("Mp5_Idle");
ammo = 30;
}
function Update ()
{
if(Input.GetMouseButton(0) && 0 <= ammo && cooldown <= Time.time)
{
cooldown=Time.time+0.1f;
SprayMP5 ();
}
else
{
StopMp5();
}
if(Input.GetKeyDown(KeyCode.R))
{
GetComponent.<Animation>().Stop("Mp5_Idle");
GetComponent.<Animation>().Play("Mp5_Reload");
StopReload();
}
}
function SprayMP5 ()
{
GetComponent.<Animation>().Play("Mp5_Shot");
GetComponent.<Animation>().Stop("Mp5_Idle");
ammo -= 1;
}
function StopMp5()
{
GetComponent.<Animation>().Stop("Mp5_Shot");
GetComponent.<Animation>().Play("Mp5_Idle");
}
function OnGUI ()
{
GUI.Label(new Rect(30, 80, 150,50), ammo.ToString());
}
function StopReload ()
{
yield WaitForSeconds(1.2);
GetComponent.<Animation>().Stop("Mp5_Reload");
GetComponent.<Animation>().Play("Mp5_Idle");
ammo = 30;
}