Hello,
I’m trying to build a Game Over Screen with the newer UI, and I followed the same steps that I used while setting up my Title Menu, but for some reason I’m having an issue. In the Inspector where the ‘GetComponent’ will usually have spaces to drag in buttons and a canvas, there is just a space displaying the ‘GameOver’ Script.
Here’s the one I have that’s working, for reference:
And here is the one that I’m having issues with:
I’m really not to great with code, but perhaps I haven’t told my script to expose them to the inspector? If I’ve done something completely wrong in my code, please let me know so I can improve! Here is a copy of my code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GameOverUI : MonoBehaviour {
int score = 0;
private bool retry;
public Canvas gameOver;
public Button retryLevel;
public Button returnMain;
void Start ()
{
score = PlayerPrefs.GetInt("Score");
gameOver = gameOver.GetComponent<Canvas>();
retryLevel = retryLevel.GetComponent<Button>();
returnMain = returnMain.GetComponent<Button>();
gameOver.enabled = true;
}
public void RetryLevel()
{
Application.LoadLevel(1); //Level that is my game
}
public void ReturnToMainMenu()
{
Application.LoadLevel(0); //Level that is the Title Menu
}
}
Also, you will probably see I have a variable declared for ‘score’ that isn’t used in the code. I have a high score that grows based on time that’s passed, and amount of power-ups picked up, and would like to add that to my ‘Game Over’ screen, but am not sure how. Any advice there would be great also!