Hey everybody !
I have an issue with DontDestroyOnLoad :
In the First Scene, the payer have the possibility to enter in a battle, which take place in an other scene.
In order to save all mobs in the battle and some other things, I use a GameObject with this code :
public string currentPlayerScene;
public float xPlayerPos;
public float yPlayerPos;
public List<GameObject> allAllies;
public List<GameObject> allEnemies;
void Awake()
{
DontDestroyOnLoad(transform.gameObject);
}
When the BattleScene is loaded, i have a script, named “BattleManager”. In this code, there is a public GameObject for the DontDestroyOnLoad GameObject which is assigned by "GameObject.FindGameObjectWithTag(“BattleSettings)” in the Start method.
The problem is : the variable isn’t assigned, so all the other methods can’t be used.
This is the Start Method of “BattleManager” :
void start()
{
enterBattleSettings = GameObject.FindGameObjectWithTag("BattleSettings");
currentPlayerScene = enterBattleSettings.GetComponent<BattleSettings>().currentPlayerScene;
xPlayerPos = -10;
yPlayerPos = 10;
allAllies = enterBattleSettings.GetComponent<BattleSettings>().allAllies;
allEnemies = enterBattleSettings.GetComponent<BattleSettings>().allEnemies;
EnterBattle(enterBattleSettings.GetComponent<BattleSettings>().allAllies, enterBattleSettings.GetComponent<BattleSettings>().allEnemies);
}
Thank you !
Bye, xyHeat