Animation not playing

Hi everyone,

I am having a problem trying to get my character to play the animation to pick up something. I am using the standard 3rd Person controller and I want to add a Pick up. When I press the T key it does work in the animator but in the game it isn’t working.

I have attached this script my character not the character controller if i do nothing happens.

Would anyone have any idea why this is doing this?

	Animator anim;
	int takeHash  = Animator.StringToHash ("Pick_boy");

	void Start () {
		
		anim = GetComponent<Animator> ();
	
	}
	
	void Update () {
		if (Input.GetKeyDown (KeyCode.T)) {
			anim.Play (takeHash);
			
		}
	}
}

Without making the instantiation a little bit slower, try doing it like this,

void Update()
{
    if (Input.GetKeyDown(KeyCode.T)) {
        gameObject.GetComponent<Animator>().Play("Pick_boy");
    }
}