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");
}
}