【发布时间】:2015-09-17 18:27:10
【问题描述】:
我有一个 mecanim 角色,我在动画师中为其设置了动画。我添加了 4 个触发器来触发不同的动画。我的问题是,按下左/右键盘按钮时触发运行动画的最佳方式是什么?我现在所拥有的是动画不断被触发,因为我在Update() 中有代码。我该怎么做才能让它只触发一次并循环播放该动画?
我有这个工作:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class AnimationController : MonoBehaviour {
Animator animator;
bool running = false;
void Start() {
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if(Input.GetButton("Horizontal")) {
if(!running) {
animator.SetTrigger("Run");
running = true;
}
}
if(Input.GetButtonUp("Horizontal")) {
animator.SetTrigger("Idle");
running = false;
}
}
}
但似乎完成此任务所需的更多,尤其是随着动作和动画列表的增长。
【问题讨论】: