Animation won't play just once and hold
I've been stuck on this for two days.
With this code:
if (walkSpeed > 5 && Input.GetAxis("Mouse X") > 0)
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Run_Turn_Right_A1_Bool", true);
}
else
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Run_Turn_Right_A1_Bool", false);
}
I start running and I move the mouse right. It triggers my bool properly.
But the animation the bool is connected to starts looping.
I can't get it to transition to anything, no matter what I do. I would like for it to play once and then stop on the last frame until the mouse isn't going to the right anymore.
Here's all the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThridPersonCharacterController : MonoBehaviour
{
public float maxWalkSpeed = 10.0f;
public float Speed;
void Update () {
float walkSpeed = Input.GetAxis("Vertical") * maxWalkSpeed;
if (walkSpeed > 5)
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Walk_A_Bool", false);
animator.SetBool("Run_A_Bool", true);
}
else
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Run_A_Bool", false);
}
if (walkSpeed >= 1 && walkSpeed <= 5)
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Walk_A_Bool", true);
}
else
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Walk_A_Bool", false);
}
if (walkSpeed == 0 && Input.GetAxis("Mouse X") < 0)
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Stand_Turn_Left_A_Bool", true);
}
else {
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Stand_Turn_Left_A_Bool", false);
}
if (walkSpeed > 5 && Input.GetAxis("Mouse X") < 0)
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Run_Turn_Left_A1_Bool", true);
}
else
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Run_Turn_Left_A1_Bool", false);
}
if (walkSpeed > 5 && Input.GetAxis("Mouse X") > 0)
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Run_Turn_Right_A1_Bool", true);
}
else
{
Animator animator = GetComponent<Animator>() as Animator;
animator.SetBool("Run_Turn_Right_A1_Bool", false);
}
// if (walkSpeed == 0)
// {
// Animator animator = GetComponent<Animator>() as Animator;
// animator.SetBool("Walk_A_Bool", false);
// }
PlayerMovement();
}
void PlayerMovement()
{
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
Vector3 playerMovement = new Vector3(hor, 0f, ver) * Speed * Time.deltaTime;
transform.Translate(playerMovement, Space.Self);
}
}
Thanks.
examples.jpg
(510.2 kB)
Comment
Your answer
Follow this Question
Related Questions
Problem importing fbx model and animations separately from Maya [Not Solved] [Help] 0 Answers
Rotate a hinge joint on its own 0 Answers
animation simple pendulum and double pendulum 1 Answer
Stuck Selected animation state Button with fake click 0 Answers
How to create a seamless looping animation, without noticing when the loop occurs? 1 Answer