using UnityEngine;
using System.Collections;
public class ResetLevel : MonoBehaviour
{
private PlayerHealth playerHealth;
public Vector3 spawnPoint;
private bool playerIsDead;
public GameObject player;
void Awake()
{
playerHealth = GetComponent<PlayerHealth>();
}
void Update()
{
if(playerIsDead)
{
Invoke("LoadedLevel", 3);
}
}
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "Player")
{
playerHealth.currentHealth = 0;
Destroy(player);
playerIsDead = true;
LoadedLevel();
}
}
public void LoadedLevel()
{
Application.LoadLevel(Application.loadedLevel);
Spawn();
}
void Spawn()
{
Instantiate(player, spawnPoint, Quaternion.identity);
}
}
Hi “Unity_Noob_Need_Help”, You have the right idea with this script. The only problem is in the method LoadedLevel(), you are calling Application.LoadLevel(Application.loadedLevel); That is restarting the entire scene and thus not running the following code.
There are two workarounds for this.
- Use DontDestroyOnLoad(gameObject); in the Awake function.
What this will do is keep this object present and NOT reset this specific object thus running the code following “Application.LoadLevel(Application.loadedLevel);”
The more preferable:
- Instead of having the Spawn() function in the LoadedLevel() function, put it in the Start() function that way it will spawn every time the scene loads.
I hope this helps, happy coding 
~nDrummR
seems issue is with Update function, you should never add
if(playerIsDead)
{
Invoke("LoadedLevel", 3);
}
in Update function, never. remove it & scripts should work!