- Home /
Question by
freemann098 · Sep 01, 2014 at 07:04 AM ·
c#gameobjectanimator
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, Vector2.zero);
//raycast stuff for input checking.
if (hit != null && hit.collider != null && Input.touchCount == 1) {
//Debug.Log ("I'm hitting "+hit.collider.name);
if(hit.collider.name == "bear_game_controller" && Input.touches[0].phase == TouchPhase.Began){
anim.SetTrigger("activate");
if(currentBaseState.nameHash = openBeer){
}
}
}
}
}
Comment
Best Answer
Answer by CapeGuyBen · Sep 01, 2014 at 08:00 AM
On line 27, you should be using the comparison operator (==) not the assignment operator (=).
Answer by Woj_Gabel_FertileSky · Sep 01, 2014 at 07:52 AM
In line 27 you need to add one equals sign :) You dont assign stuff in if checks.
if(currentBaseState.nameHash == openBeer){
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613162021im_/https://answers.unity.com/themes/thub/images/avi.jpg)