- Home /
Playing 2D animation over a Game Over dialog
I have a 2D animation I would like to play over my Game Over dialog, such that when the animation completes (and closes) the Game Over dialog is revealed.
I'm learning Unity, does anyone have a tutorial they can share with me, or advice on how to do it?
I've been able to get it working however the animation displays behind the dialog. I think I need to add a component but i'm not sure what one
thanks
Answer by guido-paglie · Sep 15, 2017 at 02:01 PM
Hi ! You can use AnimationEvents
https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html
Basically you have to put an animation event on the animation window, on the selected animation clip. And there you can call a function of a script attached to that gameobjects.
So you can add at the end of the animation ( or maybe one frame before, sometimes unity has a bug and doesn't call an event on the last frame) and there call a function which reveals the GameOver dialog.
tutorial: https://www.youtube.com/watch?v=7G3B7l4GmYQ
Hope it helps, cheers !
Answer by RCrusoe · Sep 20, 2017 at 07:56 AM
Hi @guido-paglie thanks for the info, I've read the doco and watched the vid but am still struggling....
Fyi this is the animation ('Explosion') I'm trying to display over my dialog ('WinPanel'): https://www.assetstore.unity3d.com/en/#!/content/66932
(I'm using the Explosion prefab that comes with the asset.)
Rather than calling WinPanel from an event in Explosion, I'd just like to activate both at the same time from my script using: Explosion.SetActive(true) WinPanel.SetActive(true)
I've got this working but still can't get Explosion to display over WinPanel despite ordering them correctly in the Hierarchy, in the image below I show the Inspector for Explosion:
In the next image I show the Inspector for Explosion > ExpAnimator. You can see it has an image assigned which does display over WinPanel, however its child images (Fire, Shrapnel, Smoke, Light) do not. These are the images that form the animation.
Any ideas what I'm doing wrong? thanks
Have you thought about making the animation a child of the panel?
Your answer
![](https://koobas.hobune.stream/wayback/20220612134855im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Running script/lines of code 1 Answer
how to call a class on click 1 Answer
Cant Get Dialogue Trigger Working 0 Answers
What is the best way to animate a 2D character? 2 Answers
Update anim references in script 0 Answers