Checking Animtor State Info With Hash Name

I’m trying to check this gameobjects state of animation an do something when it is in that state. I’m attempting to do this by getting the gameobject’s animator CurrentAnimatorStateInfo and check if it’s hash name is equal to a specific one. But I’m getting the error game_bear.cs(27,53): error CS0200: Property or indexer `UnityEngine.AnimatorStateInfo.nameHash’ cannot be assigned to (it is read only)

using UnityEngine;
using System.Collections;

public class game_bear : MonoBehaviour {

	private int score = 0;
	private Animator anim;
	static int openBeer = Animator.StringToHash("Base.action");
	AnimatorStateInfo currentBaseState;

	// Use this for initialization
	void Start () {
		anim = gameObject.GetComponent<Animator> ();

	// Update is called once per frame
	void Update () {
		currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
		Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
		RaycastHit2D hit = Physics2D.Raycast(pos,;
            //raycast stuff for input checking.
		if (hit != null && hit.collider != null && Input.touchCount == 1) {
			//Debug.Log ("I'm hitting ";
			if( == "bear_game_controller" && Input.touches[0].phase == TouchPhase.Began){
				if(currentBaseState.nameHash = openBeer){


On line 27, you should be using the comparison operator (==) not the assignment operator (=).

In line 27 you need to add one equals sign :slight_smile: You dont assign stuff in if checks.

if(currentBaseState.nameHash == openBeer){