Sup?我有一个空闲状态,用于我的玩家角色,这是默认状态。但是,我想要一个二级闲置。当我按下C键时,它会进入第二个空闲动画并停留在那里。当我按下x键时,它会回到默认的空闲动画。但这是问题开始的地方。当我按下C键再次切换到辅助动画时,会很快跳到第二个空闲动画,但会返回到默认动画,而无需保留或等待任何其他命令。我希望它留在我告诉它的地方。在两个空闲动画状态之间切换
此外,问题发生后,我再次点击C键,动画不会改变。但是,当我点击X键而不是此时,然后是C键后,它又一次在动画之间来回跳动。所以我认为,它'认为'它已经被切换,当它没有。如果你能告诉我该如何解决这个问题,我将成为你最好的朋友。谢谢。
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
private Animator anim;
Rigidbody2D rb;
public float Speed;
private bool aim = false;
private bool shot = false;
private bool idle = true;
public Transform arrowSpawn;
public GameObject arrowPrefab;
private bool idle2 = false;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
Movement();
Inputer();
Morph();
}
void Movement()
{
float moveH = Input.GetAxis("Horizontal");
{
rb.velocity = new Vector2 (moveH * Speed, rb.velocity.y);
}
anim.SetFloat ("Speed", Mathf.Abs (moveH));
}
void Inputer()
{
if (!aim && Input.GetKeyDown (KeyCode.S)) {
aim = true;
anim.SetTrigger ("AIm");
}
if (aim && Input.GetKeyUp (KeyCode.S)) {
shot = true;
anim.SetTrigger ("Shot");
}
if (shot) {
shot = false;
aim = false;
idle = true;
anim.SetTrigger ("Idle");
Instantiate (arrowPrefab, arrowSpawn.position, arrowSpawn.rotation);
}
}
void Morph()
{
idle = !idle2;
if (idle && Input.GetKeyDown (KeyCode.C)) {
idle2 = true;
anim.SetTrigger ("idle2");
}
if (!idle && Input.GetKeyDown (KeyCode.X)) {
idle = true;
anim.SetTrigger ("Idle");
idle2 = false;
}
}
}
我只是想他们。结果完全一样。我知道某个地方的问题与闲置的问题有关,并且您确实清理了一些代码。我没有考虑投入回报,所以非常感谢。但问题仍然存在于两个版本中。 –
哦!只是想出了最好的朋友!我在称为idle1的动画制作者中制作了一个辅助触发器。然后我把它从第二个闲置链接到第一个使用idle1,并用anim代替它。用anim替换它。用SetStrigger命令(“Idle1”);感谢您的协助! –