Coroutine wrong Behavior when scene is loaded

后端 未结 2 1305
花落未央
花落未央 2020-12-18 12:37

Ok so I have this coroutine :

 IEnumerator ShowCharTraits()
    {

        while(!hasPlayerChosen)
        {
            yield return null;
            trait         


        
2条回答
  •  太阳男子
    2020-12-18 13:01

    Ok how do I explain this. I have a singleton that acts as a data holder. While developing the scene with the game manager I had attached the singleton to the gamemanger object that hold a bunch of scripts. Now when I made the main menu I ofc added my singleton to it so I can carry info to the game scene and because of this my whole game manger object was being deleted. This is the culprit from the DataHolder :

     void Awake()
        {
            if (instance == null)
                instance = this;
            else if (instance != this)
                Destroy(gameObject);//This right here.
    
            DontDestroyOnLoad(gameObject);
        }
    

    So I changed that line to Destroy(gameObject.GetComponent(instance.GetType()));

提交回复
热议问题