Activate animation by pressing the E key within a trigger

Hi, I’m creating a horror game and I need a script to activate an animation by pressing the E key when it’s inside a trigger and it only plays once, but I do not know how to do it and I was wondering if I could send the full script in Answer in This question please, thank you.

Hi, depending on where the animator is stored, accessing the animator can be different. But lets assume its stored not on the player but the object that causes the trigger:

Animator anim;
bool alreadyPlayed = false;

// Get the Animator
void Start () => anim = GetComponent<Animator>();

void OnTriggerStay (Collider collider) =>
	if (Input.GetKeyDown (KeyCode.E) && !alreadyPlayed)
		if (anim != null){
			anim.Play ("AnimationName", 0, 0.25f);
			alreadyPlayed = !alreadyPlayed;
		}