Animation Not Playing in the Correct Way
Hi, so I'm trying to animate my character for my game to raise their shield, everything is almost working, but I'm trying to make it so then when they walk while already having their shield up, it will play the blocking and walking animation, and vise versa. However, when I raise the shield, and then start to walk, it quickly goes through the idle animation, and then the walking animation before it actually reaches the walk and block animation. I was wondering how I could get around this, and haven't been able to figure it out. Here is my code:
public NavMeshAgent nav;
public Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent <Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.Mouse1) && nav.velocity.x == 0 && nav.velocity.y == 0 && nav.velocity.z == 0) {
anim.SetBool ("Blocking (Idle)", true);
anim.SetBool ("Blocking (Walking)", false);
} else if (Input.GetKey (KeyCode.Mouse1)) {
anim.SetBool ("Blocking (Walking)", true);
anim.SetBool ("Blocking (Idle)", false);
} else if (Input.GetKeyUp (KeyCode.Mouse1)) {
anim.SetBool ("Blocking (Idle)", false);
anim.SetBool ("Blocking (Walking)", false);
}
if (Input.GetKey (KeyCode.Mouse0)) {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
nav.SetDestination (hit.point);
anim.SetFloat ("Walking", 1);
}
}
if (nav.velocity.x == 0 && nav.velocity.y == 0 && nav.velocity.z == 0) {
anim.SetFloat ("Walking", 0);
}
}
Thanks in advance for any help.
Your answer
Follow this Question
Related Questions
Unity bug makes objects glitch with square patterns 0 Answers
Unintended behavior with setting the position of an animated character in a timeline. 0 Answers
Animation Resets Position When Played: 0 Answers
My UNITY is not loading 0 Answers
Game view visual glitch, duplicating all objects in the scene 2 Answers