- Home /
Question by
PRninja8488 · Nov 03, 2014 at 09:10 PM ·
animationui4.6
4.6 play animation on game over
I'm trying to get an animation to play on the UI at game over. My research has led me to 1 of 2 problems: first, the animation would just play when the game started, so the game over screen is up the whole time. Second, after some playing around, it tells me that the animation state "gameOverAnimation" cannot be found. I can go between these two problems, but I can't find the happy medium.
Here is my relevant code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class GameController : MonoBehaviour
{
public AnimationClip gameOverAnimation;
public void GameOver()
{
gameOverText.text = "ducky 'sploded!";
gameOver = true;
if (gameOver == true)
{
animation.Play ("gameOverAnimation");
}
}
Any help would be greatly appreciated. I'm tagging this with 4.6 beta, because I couldn't find a separate place to ask about it.
Comment
Do you have an animator controller attached to the object, or are you just using the animation clip on its own?
Protip: if (gameOver == true) is redundant. Just use if (gameOver)
Your answer
![](https://koobas.hobune.stream/wayback/20220613170644im_/https://answers.unity.com/themes/thub/images/avi.jpg)