Play animation when another object is destroyed

I’m looking for some help to write a c# script, i dont have a lot of experience working with c# but i know some basics.
I have a door with an animation that makes it open and i want that animation to play when i destroy another game object, a wire in this case. How can i make my code do that?
I realize this is probably very basic but i am getting desperate.

Is your “animation” that you want to play an old legacy “Animation” - component? Or are you using the Mecanim “Animator” component?

I assume for now, that you use the old system with “Animation” component and that this component is attached to your door already.

I would suggest something like this (wrote this out of my gut without testing. Hope it works):

public class PlayAnimationWhenDestroyed : MonoBehaviour
    public Animation target;
    public string animationName;
    void OnDestroy()

Add this component to the object you are destroying and drag’n’drop the door into the “target” property. Then enter the name of the animation to play into the “Animation Name” property.

Try to set a trigger for the animation on the OnDestroy() of the GameObject that’s gonna be destroyed.

OnDestroy() event:

Setting a trigger: Unity - Scripting API: Animator.SetTrigger