Hey guys, I am working on a turn based combat system and want to switch the scene to a new one when the combat starts. But the problem I am facing is keeping the reference of the characters and enemies in the new scene as all of their instances are getting deleted when the scene load. Can someone please suggest me a way to do it properly.
You can transfer gameobjects to another scene by writing DontDestroyOnLoad(gameObject);
in your start or awake method of that game object. @deXter_47
When switching between scenes (back to the scene pre-combat), you may create a fresh new instance of the undestroyed object. Therefore, you should use a singleton reference to prevent duplicates from occuring. The script for your player, for example, may look like this:
public class Player : MonoBehaviour
{
private static Player instance;
void Awake()
{
if (instance == null)
instance = this;
else
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
}
}