Elegant way to use Animator.StringToHash in a Switch C#

Hi guys

I looked around and whilst I found some answers, I didn’t find anything this specific.
I am aware that switch needs each “case” to be a constant, but I seen this working in JavaScript so I’m hoping there’s a way for C#.

The idea is to have a switch statement for a character AI that runs animation and other things (sounds, triggers other states, movements, etc.)
public Animator anim;
public AnimatorStateInfo currentState;
public int walkForwardState = Animator.StringToHash(“Base Layer.WalkForward”);
public int idleState = Animator.StringToHash(“Base Layer.Idle”);
public int hitState = Animator.StringToHash (“Base Layer.Hit”);
public int deadState = Animator.StringToHash (“Base Layer.Dead”);
public int attackState = Animator.StringToHash (“Base Layer.Attack”);
public int patrolState = Animator.StringToHash (“Base Layer.Patrol”);

void Update()
{
switch (currentState.nameHash)
		{
		case 961959321:
			hasAttacked = false;
			foreach (GameObject zombie in zombies)
			{
				if (Vector3.Distance (transform.position, zombie.transform.position) < 8.0f)
					zombie.GetComponent<ZombieControl>().SetWalking(true);				
			}
			transform.LookAt(playerTransform);
			break;

		case 1432961145:
			if ((Physics.Raycast (new Vector3(transform.position.x, transform.position.y+0.5f, transform.position.z), transform.forward, out hit, 20) && hit.collider.gameObject.tag == "Player") || distance < 2.0f)
			{
				anim.SetBool("walking", true);
			}			
			break;

		case -1005802792:
			if (anim.GetBool ("hit")) {damage++;}
			if (damage >= 5)
			    anim.SetBool ("dead", true);
			anim.SetBool("hit", false);
			break;

		case 1684585544:
			Destroy(gameObject, 6.0f);
			break;

		case 1130333774:
			if (!hasAttacked)
			{
				ApplyDamage();
				hasAttacked = true;
			}
			anim.SetBool ("withinReach", false);
			break;

		case 258246660:
			transform.LookAt (GameObject.Find ("wayPoint"+wayPointIndex).transform);
			float distanceToWayPoint;
			distanceToWayPoint = Vector3.Distance (transform.position, GameObject.Find("wayPoint"+wayPointIndex).transform.position);
			if (distanceToWayPoint < 1.0f)
				wayPointIndex++ ;
			if(wayPointIndex>4)
				wayPointIndex = 1;
			break;

		default:
			break; 
		}
}

now the problem with this is that i can easily break and let’s be honest is a pain to read and hard to revisit. Isn’t there a way that the variables at the top can be made to work as constant? tried to initialise them as const int state = blah.StringToHash(“BlaH”), also tried to initialise with a construct, on Start() and on Awake() with no success.

Thank you for your time!

bump? :slight_smile: