【发布时间】:2017-08-27 19:10:51
【问题描述】:
我实际上可以对敌人执行此操作,但由于某种原因,如果是玩家,我无法使其工作。
看,播放器处于默认的空闲动画中。当我从相反的方向按下箭头键时(默认是游戏开始时的右侧->),我希望它在精灵翻转其 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");
}
}
【问题讨论】:
标签: c# animation sprite delay unity2d