How can I activate the animation of a specific gameobject before destroying it?

So I have a spawner which creates gameobjects constantly. This gameobjects have two animations (the “common one” and the “death one”).

When there’s only one gameobject and gets touched everything works fine. But when there are more than one spawned objects in the scene and I click on one of them, it gets destroyed (as it should) but the one that gets the death animation is the newest object in the scene not the one I touched.

So I want to know if there’s a way in which I can state that the object that is touched (and therefore destroyed) is the one that must activate the “death animation”?

Thanks in advance for the help :slight_smile:

c# Code of the destructor and animation trigger:

using UnityEngine;
using System.Collections;


public class touchDestructor : MonoBehaviour {
	
	static Animator anim;

	void Start () {
		anim = GetComponent<Animator>();
	}
		
	void Update () {
	}
		
	IEnumerator OnMouseDown (){
		int increment = 10;
		GameObject.FindGameObjectWithTag ("ScoreHandler").SendMessage ("UpdateScore", increment); //This is for a score


		anim.SetTrigger ("isPressed");
		
		yield return new WaitForSeconds (0.25f); //Delay time for letting the animation work
		Destroy (this.gameObject);
	}
}

That’s because anim is static and a new object always sets anim to it’s own Animator.
Instead you could get the Animator component in OnMouseDown.

Note that Destroy takes a time parameter.