【发布时间】:2014-10-09 16:54:07
【问题描述】:
我刚开始使用 Unity 创建我的第一个游戏,但我已经卡住了。我试图为狼牙棒设置动画并在单击鼠标左键时运行动画,但出现了这个奇怪的错误:
MissingComponentException: There is no 'Animation' attached to the "Mace" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "Mace". Or your script needs to check if the component is attached before using it.
UnityEngine.Animation.Play (System.String animation) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/Animations.cs:569)
MeleeSystem.Update () (at Assets/MeleeSystem.js:11)
参考这个脚本:
#pragma strict
var theDamage : int = 50;
var Distance : float;
var maxDistance : float = 1.5;
var TheMace : Transform;
function Update (){
if(Input.GetButtonDown("Fire1")){
TheMace.animation.Play("Attack");
var hit: RaycastHit;
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit)){
Distance = hit.distance;
if(Distance < maxDistance ){
hit.transform.SendMessage("ApplyDamage", theDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
第 11 行是:TheMace.animation.Play("Attack");
我已经做了所有应该做的事情。这是我的工作区的屏幕截图:
地点:
1) 是近战 - 你可以看到锤是它的孩子。 2)近战脚本。 3) TheMace 变量被正确赋值。
我知道我在这里错过了一小部分,但作为一个完整的初学者,我就是无法发现它。可以推一下吗?
编辑: 检查员截图:
【问题讨论】:
-
你能展示附加到 Mace 对象上的组件吗?该错误非常清楚地定义了问题所在。
-
@SirBraneDamuj Mace 对象包含一个名为 Grip 的圆柱体 - 这就是它所包含的全部内容。
-
我不是指它的子对象,我是问附加了哪些组件。换句话说,单击 Mace 并查看其检查器窗口(最右侧的窗格)。您应该会在最顶部看到一个 Transform,然后是所有其他组件。
-
@SirBraneDamuj 抱歉,我刚刚编辑了我的帖子。
标签: animation unity3d unityscript