Only one Instantiated player that used Don’t Destroy On Load will be spawned the others will be removed immediately.
Don’t Destroy On Load Script:
void Awake()
{
InstantiateController();
}
private void InstantiateController()
{
if (Instance == null)
{
Instance = gameObject;
DontDestroyOnLoad(gameObject);
}
else if (this != Instance)
{
Destroy(gameObject);
}
}
Scene Detection:
bool changed = false;
bool changed2 = true;
bool changed3 = false;
// Update is called once per frame
void Update()
{
Scene scene = SceneManager.GetActiveScene();
if (scene.name == "PlayScene" && !changed)
{
changed = true;
changed2 = false;
changed3 = false;
transform.position = new Vector3(0, -3.485f);
GameObject.Find("WaveHandler").GetComponent<Wave>().startingTargets.Add(transform);
plrnum = GameObject.Find("WaveHandler").GetComponent<Wave>().startingTargets.Count;
}
if(scene.name == "MainMenu" && !changed2)
{
changed = false;
changed2 = true;
changed3 = false;
transform.position = new Vector3(0, -3.485f);
GameObject.Find("WaveHandler").GetComponent<Wave>().startingTargets.Add(transform);
plrnum = GameObject.Find("WaveHandler").GetComponent<Wave>().startingTargets.Count;
}
if (scene.name == "TestScene" && !changed3)
{
changed = false;
changed2 = false;
changed3 = true;
transform.position = new Vector3(0, -3.485f);
GameObject.Find("WaveHandler").GetComponent<Wave>().startingTargets.Add(transform);
plrnum = GameObject.Find("WaveHandler").GetComponent<Wave>().startingTargets.Count;
}
}
Input Manager:
If you need more info just tell me! Thanks!!!