My Problem: I don’t know where to set my bool spawnFlag to false. If I set it within my base-class, only one object is respawned properly. If I don’t set it at all, with every update all the objects are respawned (which means technically the respawn logic itself is working, but it needs to stop after the respawn of those objects). I may have gone about this all wrong, but with how I have it laid out currently, I just need to figure out how to properly end the spawning of the objects inheriting my classObject base-class once my main character spawn triggers.
I have a GameManager class that has a method to spawn the main character.
public void SpawnPlayer(Vector3 spawnPos) {
spawnFlag = true;
currentPlayer = (Instantiate(player,spawnPos,Quaternion.identity) as GameObject);
cam.SetTarget(currentPlayer.transform);
}
The other characters need to be respawned at their default spawn position upon respawn of the player. The other characters inherit the base-class ‘classObject’. Within this is a method that is called in the Update() of the sub-class to allow respawning.
//Clears trigger flag and sets position to default
public void AllowRespawn() {
if (gm.spawnFlag) {
Debug.Log("Respawning Object: " + this.gameObject);
isTriggered = false;
transform.Translate(Vector3.zero);
transform.position = spawnPos;
}
}