Trying to play an animation using the 'E' key.

I’m trying to animate a tree I have using the ‘E’ key. I have 3 separate animations for it; Idle, Fall, and Down (Down meaning it stays down).

This is the code I have:

using UnityEngine;
using System.Collections;

public class TreeFall : MonoBehaviour {

public GUIText textHints;

bool Fall = false;

void Start () {
	
}

void OnTriggerEnter(Collider col){
	textHints.SendMessage ("ShowHint", "

That tree looks like it can be pulled down.");

	if(col.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.E)){
		print ("player has pressed e");
			animation.Play("Fall");
	}
}

void Update () {

}

}

The box collider I’m using works and everything, I’ve used ‘print’ to help me ensure this, it’s just that whenever I enter the triggerzone, and hit the ‘e’ key, nothing happens, and my animation doesn’t play. What am I doing wrong?

OnTriggerEnter is only called once upon each contact point. So what your code is doing is checking if the User press the key at the same time of a collision with the target. Use OnTriggerStay instead.