I’m making a platformer and my setup goes like this in the first picture you will see the player, a ground piece, and the camera with a killzone childed to it.
For your convience here is the code in question. The only other script that has anything to do with respawning is the Player script, which calls the Respawn function
using System.Collections;
using UnityEngine;
public class LevelManager : MonoBehaviour
{
[SerializeField] float waitToRespawn = 2f;
Player player;
ResetOnRespawn[] objectsToReset;
void Start()
{
player = GetComponent<Player>();
objectsToReset = FindObjectsOfType<ResetOnRespawn>();
}
public void Respawn()
{
StartCoroutine("RespawnCo");
}
public IEnumerator RespawnCo()
{
player.gameObject.SetActive(false);
yield return new WaitForSeconds(waitToRespawn);
player.transform.position = player.respawnPos;
player.gameObject.SetActive(true);
}
}
This code seems to be implying that the LevelManager is attached to the player object. Is that right? If so, you are disabling the very object that is running this coroutine - a big no-no. Your LevelManager script should be attached to a different GameObject hierarchy entirely or you should find a different way of ‘disabling’ the player object (like disabling input and rendering components only).