I always get this error 'Animator' does not contain a definition for 'StringtoHash'

Here is the error:

Assets\animationStateController.cs(14,34): error CS0117: ‘Animator’ does not contain a definition for ‘StringtoHash’
it doesnt give me the line of the code

Here is my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class animationStateController : MonoBehaviour
{
Animator animator;
int isWalkingHash;

// Start is called before the first frame update
void Start()
{
animator = GetComponent();
isWalkingHash = Animator.StringtoHash(“isWalking”);
}

// Update is called once per frame
void Update()
{
bool isWalking = animator.GetBool(isWalkingHash);
bool forwardPressed = Input.GetKey(“w”);
// if player presses w key
if (!isWalking && forwardPressed)
{
//then set the isWalking boolean to be true
animator.SetBool(isWalkingHash, true);
}

// if player is not pressing w key
if(isWalking && !forwardPressed)
{
// then set the isWalking boolean to be false
animator.SetBool(isWalkingHash, false);
}
}
}

Capitalisation error, should be Animator.StringToHash

Why are you using restricted mode in your editor? Whatever that is I assume it is preventing the editor from highlighting the error.

Thank you so much MUNCHY2007. I am very sorry. I spent 4 hours trying to fix this problem. Thank you so much. You are a lifesaver. I’m a beginner.

1 Like