- Home /
Other
Need help with my Respawn Script
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;
}
}
Answer by SaguG · Feb 03, 2021 at 10:44 PM
why did you do this? just use SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex);
and it will restart your current scene (Level)
Yeah you are right, still doesn't fix the issue.
However it does clear stuff up, so thanks.
Np (i didnot even understand what is your problem)
Follow this Question
Related Questions
Reloading a Scene when I die doesn't work for the second level. 0 Answers
Cancel loading a level using LoadLevelAsync? 2 Answers
buttons not being able to be clicked? 1 Answer
can someone tell me whats wrong with this code? 1 Answer
Start points don't work when I switch from the title screen, to the playable scene 0 Answers