- Home /
Animation not playing! Help needed!
Hi, so I am new to Unity and I have created an animation to play when my character gets damaged that makes them flash red. I called this anim "Player_Damaged" and applied to to the animation component on my player. I have set it to legacy and vice versa but neither work. Legacy mode comes up with no errors however, and this randomly started happening as it was working fine before. I have remade the animation 20+ times and have tried all sorts of things! Please help me out. Here is some code:
public void Damage(int dmg){
currentHP -= dmg;
gameObject.GetComponent<Animation>().Play("Player_Damaged");
Answer by badadam · Jan 14, 2019 at 09:06 AM
You make red flash anim. I think you use Image component for flash red anim. But you add Animation component to your Player. You should add the animation component to the red flash object.
public class PlayerScript : MonoBehaviour
{
//drag red flash object to the instance below
public GameObject redFlashObject;
public int currentHP;
public void Damage(int dmg)
{
currentHP -= dmg;
redFlashObject.GetComponent<Animation>().Play("Player_Damaged");
}
}
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Setting animator parameter on a single instance of a prefab sets the parameter for all instances 3 Answers
Multiple Animation Controllers 1 Answer
Animation Parameters Not Working Correctly 0 Answers
How to start an animation by the exit animation frame 0 Answers