Play death animation triggered from another object...

Hey guys,

I’ve been wrestling with a bit of code and hoped u could help. I have a ball that has a box connected to it through a empty object. What I’ve set up in the ball control is a trigger which tells the ball and the box to die after 1 second.

	void OnTriggerEnter(Collider other) 
	{
		
		
		if (other.tag == "Destroy")
		{
			_GameManager.GetComponent<GameManager>().Death();
			Destroy(gameObject,1); 
		}
		if (other.tag == "Destroy")
		{
			_GameManager.GetComponent<GameManager>().Death();
			Destroy (GameObject.FindWithTag("Box"),1);
		}

What I want to do is also play an animation that’s in the box before it’s destroyed. I have an animation in the box object set up, I just need to understand how to add a bit of script to the ball player control to play it.

Thanks in advance.

Rich

1 Answer

1

You would get the Animation component of the object and tell it to play an animation:

For example:

box.GetComponent ().Play (“DeathAnimation”);

where “DeathAnimation” is the name of the AnimationClip.