When i let go of mouse 0 the animation stops even if its not done. Can you tell me so when you let go of mouse 0 the animation finishes instead of just stops.
Shooting animations shouldn’t be looping. You should handle that in your shooting logic. You would fire the animation everytime you shoot a bullet.
The point of looping animations is that they are never done so you need the animation to be a “normal” once-animation.
var rateOfFire = 5.0;
private var shootDelay = 0.0;
private var shootTimeOut = 0.0;
function Start()
{
var shootAni = animation["m4shoot"];
shootDelay = (1.0/rateOfFire);
// This will adjust the speed of the animation ot match the rate of fire
shootAni.speed = shootAni.length / shootDelay;
shootAni.wrapMode = WrapMode.Once;
}
function Update ()
{
if(Input.GetKey("mouse 0"))
{
if (Time.time > shootTimeOut)
{
shootTimeOut = Time.time + shootDelay;
animation.Play("m4shoot");
// shoot your bullet here
}
}
}