【问题标题】:How to stop GameObject duplications when reloading a scene?重新加载场景时如何停止游戏对象重复?
【发布时间】:2022-10-01 02:16:05
【问题描述】:

我正在制作一个玩家可以在关卡之间来回切换的游戏。我使用“DontDestroyOnLoad”将我的播放器放在它们之间,但是每当我重新加载场景时,它都会复制播放器以及我想要保持加载的所有其他内容。有谁知道对此有任何简单的解决方法?我是编程新手,所以请保持简单。

    标签: unity3d 2d scene scene2d


    【解决方案1】:

    可能你需要写这样的东西:

    public static <TypeName> instance = null;
    void Awake() {
      if (instance != null) {
        Destroy(gameObject);
      } else {
        instance = this;
        DontDestroyOnLoad(gameObject);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-02
      • 1970-01-01
      • 2020-02-05
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多