Code (CSharp): if (tPressed) { animator.SetBool(IsTalkingHash, true); } else { animator.SetBool(IsTalkingHash, false); }
Not sure why you needed 4 posts to say that. ... Question... are you certain that the bool parameter "IsTalking" exists on that 'animator'? If you change the SetBool calls to: Code (csharp): animator.SetBool("IsTalking", true); Does it work? Lets rule out if hash has anything to do with it at all...
Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimationState : MonoBehaviour { Animator animator; int IsRunningHash; int IsTalkingHash; // Start is called before the first frame update void Start() { animator = GetComponent<Animator>(); IsRunningHash = Animator.StringToHash("IsRunning"); IsTalkingHash = Animator.StringToHash("IsTalking"); } // Update is called once per frame void Update() { bool forwardPressed = Input.GetKey("w"); bool leftPressed = Input.GetKey("a"); bool downPressed = Input.GetKey("s"); bool rightPressed = Input.GetKey("d"); bool tPressed = Input.GetKeyDown("t"); bool tNotPressed = Input.GetKeyUp("t"); if (forwardPressed || leftPressed || rightPressed || downPressed) { animator.SetBool(IsRunningHash, true); } else { animator.SetBool(IsRunningHash, false); } if (tPressed) { animator.SetBool("IsTalkingHash", true); } if (tNotPressed) { animator.SetBool("IsTalkingHash", false); } } }
Look, you asked a question because you have an issue. Lordofduct gave you a specific change you should try. If that doesn't work as well, your issue is most likely that the animator you're using does not have a parameter called "IsTalking". If that's the case there is nothing you can do on the code side to make it work. You have to look at your animator first. ps: You know that you can edit your posts? Please stop posting such micro-fragments as seperate independent posts.
You didn't answer my questions though. If you'd like help we're going to need more information. I see you actually attached more code for context, but as Bunny83 pointed out... we need to rule out that the animator just isn't configured correctly or not. And like they said... if it's that, there's no amount of code that can fix that.
Sorry, so if you look at the code I put what you told me and it didn't work, and the reason I made a bunch of posts was because it wouldn't work when I put all those code fragments together in one post, and yes I am certain that the "IsTalking" parameter is in the animator