Question by
zakaria92 · Jul 16, 2017 at 10:16 AM ·
c#unity 5error message
UnassignedReferenceException: The variable UI of MenuManager has not been assigned.
image for error :
image for mono develop :
code in monodevelop :
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class MenuManager : MonoBehaviour {
public static MenuManager instance;
public GameObject UI;
public GameObject Controller;
public GameObject LevelComplete;
public GameObject GameOver;
public GameObject GamePause;
public GameObject Loading;
void Awake(){
instance = this;
UI.SetActive (true);
Controller.SetActive (true);
LevelComplete.SetActive (false);
GameOver.SetActive (false);
GamePause.SetActive (false);
Loading.SetActive (false);
}
public void Pause(){
if (Time.timeScale == 1) {
GamePause.SetActive (true);
Time.timeScale = 0;
} else {
GamePause.SetActive (false);
Time.timeScale = 1;
}
}
public void Restart(){
GlobalValue.checkpoint = false;
GlobalValue.isUsingJetpack = false;
Time.timeScale = 1f;
Loading.SetActive (true);
SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);
}
public void MainMenu(){
GlobalValue.checkpoint = false;
GlobalValue.isUsingJetpack = false;
Time.timeScale = 1f;
Loading.SetActive (true);
SceneManager.LoadScene ("Menu");
}
public void ShowGameOver(){
StartCoroutine (ShowMenu (1, GameOver));
}
public void ShowLevelComplete(){
StartCoroutine (ShowMenu (1, LevelComplete));
}
public void NextLevel(){
GlobalValue.checkpoint = false;
GlobalValue.isUsingJetpack = false;
Loading.SetActive (true);
GlobalValue.levelPlaying++; //
SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 1);
}
IEnumerator ShowMenu(float time,GameObject Menu){
yield return new WaitForSeconds (time);
Menu.SetActive (true);
}
}
Please help me :)
unity-error.png
(26.1 kB)
22.png
(64.8 kB)
Comment
Answer by LedomDeveloping · Jul 16, 2017 at 10:37 AM
Did you set a value for UI in the Inspector window, by dragging the right GameObject in the variable box?
I do not think I did , Or maybe I did it by mistake, I am a beginner in this field,
i want delete variable box ,
How do I know the variable box causing the error ?
Your answer
![](https://koobas.hobune.stream/wayback/20220612130407im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My game script is fine but I'm still getting unexpected class error 0 Answers
Survival Shooter Error CS0120 1 Answer
NullReferenceException: Error from the GetStyle() - Method 1 Answer
[Help] I keep getting an error with blank message when I create a C# script. 3 Answers
Nav Mesh Problem with SetDestination 1 Answer