In my game I have dynamite and when it touches an object it is supposed to disappear and play the explosion animation once but when it touches the object the animation keeps on looping. Any tips to make it play only one time? I will reward anyone who tells me how to play the animation once with one reputation point =). Thanks!
On the actual animation file itself, by default unity always sets “Looping” to true.
Find the animation file you want, uncheck the looping box, done.
Let me help you out.
If I understand you want the animation to play when something enters the collider and then stop playing after one loop then destroy the object? I’m going to go with your example and see you call this in start; there are two ways to do this, I’ll show you the Invoke() method.
For this to work, first setup a public float called time, or just define the time in the code where I wrote time:
private void Start()
{
Invoke("Stop", time);
}
then do something like this:
private void Stop()
{
Stop = true;
//I would have a reference to the animator component here to set that bool to stop, I don't see it in your script but mine would look like this: animator.SetBool("Stop" Stop);
Destroy(this.gameObject);
}
I’m not sure how you’re animations are triggered, the example you showed just has it in Start, so I hope this is what you’re trying to achieve.
@skatesa207 Thanks for the help but I already tried that. It did not work =/.