For some reason the respawn script works fine in the beginning scene. However when I move to the next scene and kill myself there. I don’t respawn, all I get is “Display 1, no cameras rendering”. I put a logged the time when I respawn to print out the current scene that I am in. It looks fine there so I don’t know what else could be the problem.
note: I am getting the current scene that the player is in, then reloading it when my player dies.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SpawnScript : MonoBehaviour
{
private SceneManager sceneManager;
public GameObject player;
public GameObject cam;
private void Awake()
{
Application.targetFrameRate = 300;
}
public void Respawn()
{
StartCoroutine(ReloadScene());
GameObject.FindGameObjectWithTag("Player").transform.position = GameObject.FindGameObjectWithTag("SpawnPoint").transform.position;
}
IEnumerator ReloadScene()
{
string sceneName;
Scene currentScene = SceneManager.GetActiveScene();
sceneName = currentScene.name;
Debug.Log(sceneName);
SceneManager.LoadScene(sceneName);
SceneManager.MoveGameObjectToScene(player, currentScene);
SceneManager.MoveGameObjectToScene(cam, currentScene);
yield return null;
}
}