Question by
Nosmo · Jan 25, 2018 at 02:36 PM ·
ontriggerentertagplayanimation.playget component
How to start an animation by entering a trigger
Im trying to play an animation of a zombie eating when it enters the trigger of a sphere, when it enters the trigger the ball changes material so i know thats working
code so far:
public Animator anim;
void Start ()
{
anim = GetComponent<Animator> ();
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == "goal") {
anim.Play("Zombie_Eating");
}
this was another attempt:
private Animation Zombie_Eating;
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == "goal") {
this.GetComponent<Animation>().Play("Zombie_Eating");
}
}
If you can come up with any suggestions I would be most grateful :)
Thank you
Comment
Have you any error in your console? Are you sure the gameobject colliding with your zombie as the tag "goal"? (and not "Goal", or "GOAL" for instance). Put a simple Debug.Log( col.gameObject.tag");
outside of your condition to make sure the collision is detected.