每次使用此代码按空格键时,我都会尝试制作动画:
using UnityEngine;
using System.Collections;
public class ArmSwipe : MonoBehaviour {
Animation me;
void Start (){
me=GetComponent<Animation>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Space)){
me.Play();
}
}
}
每次我运行它都会出现此错误
MissingComponentException:没有&#39;动画&#39;附在&#34; Arm&#34;游戏对象,但脚本正试图访问它。 您可能需要将动画添加到游戏对象&#34; Arm&#34;。或者您的脚本需要在使用之前检查组件是否已连接。
UnityEngine.Animation.Play (PlayMode mode)
UnityEngine.Animation.Play ()
ArmSwipe.Update () (at Assets/Scripts/ArmSwipe.cs:18)
编辑:
答案 0 :(得分:0)
你的GameObject Arm需要附加一个动画。您似乎没有将这样的动画附加到Arm上。你能附上场景图的截图和Arm对象的检查员属性吗?
此外,您可能应该像目前一样使用Input.GetKeyUp
而不是KeyDown。 KeyDown将简单地导致动画在每次更新时重新播放,它看起来像是冻结或口吃。