我刚开始使用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变量。
我知道我在这里错过了一小部分,但作为一个完整的初学者,我无法发现它。你能帮我推吗?
编辑: 检查员截图: