using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RewindTime : MonoBehaviour
{
public GameObject playerPrefab;
private Scene ThisScene;
void Start()
{
ThisScene = SceneManager.GetActiveScene();
}
void Onstart()
{
var player = GameObject.FindGameObjectWithTag(“Player”);
if (player == null)
{
player = Instantiate(playerPrefab);
DontDestroyOnLoad(player);
}
}
void Update()
{
{
if (Input.GetKeyDown(KeyCode.R))
SceneManager.LoadScene(ThisScene.name);
}
}
}
[/code]
my goal is to reload the scene without reloading the player but the best i can do is create two player
I cant figure out whats wrong with this please help
You don’t call OnStart() so this code doesn’t get executed.
Also, why are you instantiating and marking the player undestroyable in the script not related to the player? If the player has already been created and is not marked as undestroyable, then this code will not work and the player will be destroyed.
And Application.LoadLevel() is obsolete. Use SceneManager.LoadScene().
its related to the player because my goal is to reset the entire scene but save eerything about the player and not delete it and i have edited the script to i think reflect your changes and it still is not working