0
之前播放2D动画实际上,我是能够与敌人要做到这一点,但由于某种原因,我不能让它工作,如果它的玩家。翻转在Unity精灵C#
看到,玩家在默认情况下,空闲的动画。当我从相反的方向按下箭头键时(它在游戏开始时默认是右键 - >)时,我希望它在精灵翻转其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");
}
}