【问题标题】:Unity Animator component being null in different scenesUnity Animator 组件在不同场景中为空
【发布时间】:2020-11-21 02:38:59
【问题描述】:

我在一个统一场景中制作并动画化了玩家精灵,并将游戏对象保存为预制件。在我创建的场景中,它的动画效果非常好,但每当我在另一个场景中尝试预制件时,它就会中断。经过一些调试,其他场景中的Animator组件似乎为空,并且在原始场景中有相关数据。以下是我用来在代码中获取对动画师的引用的方法,该代码在原始场景中有效,但在其他场景中无效。

private Animator myAnim; 

void start(){
    myAnim.getComponent<Animator>();
    if(myAnim != null)
    {
        print("myAnim Exists"); //this happens in the original scene but not in the others
    }
}

void update(){
    myAnim.SetFloat("moveX", myRB.velocity.x); //where the red error points to at runtime. Says an object reference doesn't exist
}

【问题讨论】:

  • 动画师是否在您的预制件中正确连接?
  • 我相信是的。我可以删除预制件并将其拖回原始场景中并且它可以工作,并且场景中的预制件没有任何更改应用于项目文件夹中的预制件

标签: unity3d


【解决方案1】:

播放器有一些与错误代码无关的其他预制件,它需要在原始场景之外不存在的其他场景中引用这些预制件。不知道为什么这个错误让我大吃一惊,但至少现在已经解决了。

【讨论】:

    猜你喜欢
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多