【问题标题】:Strange MissingComponentException while everything looks ok奇怪的 MissingComponentException 而一切看起来都很好
【发布时间】: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


【解决方案1】:

您的对象附加了一个Animator 组件。它需要有一个Animation 组件。

Animator 用于操作 Mecanim 动画。 Animation 用于播放随模型导入的旧动画片段。

【讨论】:

  • 嘿,我知道发生了什么。现在它说:The AnimationClip 'Attack' used by the Animation component 'Mace' must be marked as Legacy. 我在这里错过了什么? :(
  • 您必须在您导入的模型上找到动画剪辑并更改其中一项设置(它的名称现在让我无法理解)。这是一个下拉菜单,其中一项设置是旧版。 docs.unity3d.com/Manual/Animations.html这可能会帮助你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-02
  • 1970-01-01
  • 2021-03-25
  • 2015-03-20
  • 2011-07-19
相关资源
最近更新 更多