Я действительно смог сделать это с врагом, но по какой-то причине я не могу заставить его работать, если это игрок.
Видите ли, игрок по умолчанию находится в режиме ожидания. Когда я нажимаю клавишу со стрелкой в направлении, противоположном ее направлению (по умолчанию это право при запуске игры ->), я хочу, чтобы она воспроизводила анимацию поворота до того, как спрайт перевернется по своей шкале x.
Однако то, что он делает прямо сейчас, когда я нажимаю клавишу со стрелкой, чтобы повернуть его, заключается в том, что сначала он быстро переворачивает спрайт, затем выполняет анимацию, как если бы он еще не был перевернут, а затем снова переворачивает в другом направлении.
В моем аниматоре у холостого хода нет времени выхода на узел переворота, а у узла переворота есть время выхода обратно в режим ожидания, на всякий случай, если вы спросите. Я пробовал запускать таймер здесь и там, но пока безуспешно. Кто-нибудь может помочь, пожалуйста?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class tulMoveMount : MonoBehaviour {
private Animator anim;
private Rigidbody2D rb;
public Image manaBar;
public LayerMask whatIsGround;
private bool grounded = false;
public Transform groundCheck;
public float groundCheckRadius;
private bool goRight = true;
private bool jump;
private bool turn = false;
private bool idle = true;
private bool mountOff;
private bool turnComplete = false;
public float runSpeed;
public float walkSpeed;
private float move;
public float turnDelay = 2.25f;
public float timer3 = 2.26f;
void Start ()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
void Update ()
{
grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
timer -= Time.deltaTime;
turnDelay -= Time.deltaTime;
HandleMovement ();
}
void HandleMovement()
{
float move = Input.GetAxis ("Horizontal");
float moveV = Input.GetAxis ("Vertical");
{
rb.velocity = new Vector2 (move * walkSpeed, rb.velocity.y);
anim.SetFloat ("walkSpeed", Mathf.Abs (move));
}
if (!goRight && move > 0) {
FlipConditions ();
Invoke ("ResetValues",timer3 );
Flip ();
turnComplete = false;
}
if (goRight && move < 0) {
FlipConditions ();
Invoke ("ResetValues",timer3 );
Flip ();
}
}
void FlipConditions()//
{
idle = false;
turn = true;
anim.SetTrigger ("turn");
idle = true;
anim.SetTrigger ("idle");
}
void Flip()
{
goRight = !goRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
turnComplete = false;
}
void ResetValues()
{
idle = true;
anim.SetTrigger ("idle");
}
}