- Home /
Question by
Lukeflisberg · Aug 14, 2020 at 07:55 AM ·
2d2d game2d animation
How do you add a timed animation
I have a pickup system in unity2D. When I do a collision with the object I collect it and it disappears. When you collide with it, it then plays an animation and I only want that animation to play for a second. HOW?
Comment
Best Answer
Answer by ben-rasooli · Aug 14, 2020 at 12:25 PM
Use a coroutine and stop the animation playback manually.
void OnCollisionEnter2D(Collision2D collision)
{
Invoke(nameof(stopAnimation), 1.0f);
}
void stopAnimation()
{
GetComponent<Animation>().Stop();
}
Your answer
Follow this Question
Related Questions
Stuttering in simple 2D game using interpolation? 1 Answer
How to sync animation if animation should be use with specially object 0 Answers
How to create a delay before playing an animation 1 Answer
What is the best/easiest way to align a 2D rigidbody to specific sections of a sprite? 1 Answer
Problem with Scrip for sprites 1 Answer