Question by
Ray116GA · Apr 25, 2016 at 12:46 PM ·
restart gamelevelload
Reload Level button at death screen
Hi im working on a little 2D-Platformer and made a deathscreen on which the Player gets when he collides with an enemy. The only Problem i have now is that the restart button wont reload the current Level. Pls help me im tried almosst everything now. here my script for enemies :
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class CollisionDeath : MonoBehaviour {
public GameObject DeathScreen;
public GameObject thePlayer;
public GameObject Spikes;
private bool deathScreen;
public string LevelToLoad;
// Use this for initialization
void Start () {
DeathScreen.gameObject.SetActive(false);
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.name == "Mario")
{
Debug.Log("wawawa");
thePlayer = other.gameObject;
other.gameObject.SetActive(false);
DeathScreen.gameObject.SetActive(true);
SceneManager.LoadScene(LevelToLoad); //Application.LoadLevel("DeathScreen");
Time.timeScale = 0f;
thePlayer.gameObject.SetActive(true);
}
}
}
and the script for the deathscreen:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class DeathScreen : MonoBehaviour
{
public string Restart;
public void restartGame ()
{
Debug.Log("restart1");
Time.timeScale = 1f;
Debug.Log("restart");
int scene = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(scene, LoadSceneMode.Single);
}
}
I also set an onlick() on my button that goes to the function DeathScreen.restartGame (:/)
Comment