Я изменяю состояние анимации, используя код и ввод с мобильного джойстика.
if (joystick.Vertical > joystick.Horizontal)
{
if (joystick.Vertical > threshhold) //Forward
{
foreach (AnimatorControllerParameter parameter in animator.parameters)
if (parameter.type == AnimatorControllerParameterType.Bool)
animator.SetBool(parameter.name, false);
animator.SetBool("isRunningForward", true);
}
else if(joystick.Vertical < -threshhold) //Backward
{
foreach (AnimatorControllerParameter parameter in animator.parameters)
if (parameter.type == AnimatorControllerParameterType.Bool)
animator.SetBool(parameter.name, false);
animator.SetBool("isRunningBackward", true);
}
}
else
{
if (joystick.Horizontal > threshhold) //Right
{
foreach (AnimatorControllerParameter parameter in animator.parameters)
if (parameter.type == AnimatorControllerParameterType.Bool)
animator.SetBool(parameter.name, false);
animator.SetBool("isRunningRight", true);
}
else if (joystick.Horizontal < -threshhold) //Left
{
foreach (AnimatorControllerParameter parameter in animator.parameters)
if (parameter.type == AnimatorControllerParameterType.Bool)
animator.SetBool(parameter.name, false);
animator.SetBool("isRunningLeft", true);
}
}
if(Mathf.Abs(joystick.Vertical) < 0.5 && Mathf.Abs(joystick.Horizontal) < 0.5)
{
foreach (AnimatorControllerParameter parameter in animator.parameters)
if (parameter.type == AnimatorControllerParameterType.Bool)
animator.SetBool(parameter.name, false);
}
По некоторым причинам «isRunningBackwards» и «isRunningLeft» не работают должным образом.
Когда я перемещаю джойстик назад, включается левое состояние анимации снимок экрана моего редактор