Hello,
While button is pressed, I am spawning an object in update() once a second, and I turn animation on upon spawning the projectile.
The animation cycle is set to be 1 second in the animator. So ideally, the animation should be coordinated with spawning the new projectile.
However, the animation is running faster than 1 second, and if I keep holding the button, the error accumulates and it is obvious that the two are not in sync.
In other words, although my animation is supposed to last 1 second, it is completing in around 0.9 seconds!
My logic is something like this in the update()
update()
{
fireTimer += Time.deltaTime;
//...
if (fire > 0.5 && fireTimer > 1f) // fire > 0.5 implies button is pressed
{
fireTimer = 0;
ac.enabled = true; // enables animation controller
// instantiate object...
}
else if(fireTimer > 1f)
{
ac.enabled = false;
}
}