- Home /
LoadLevel Doesn't have script
i have a main menu scene, that goes to the game scene without problems, but when i go back to the menu, the menu script doesn't show. Any solutions?
Main Menu
private var canShow : boolean = false;
var Skin : GUISkin;
private var Name : String;
var playerName : String;
private var lastScore : int;
private var myscore : int;
function Awake()
{
Name = PlayerPrefs.GetString("MyName");
playerName = Name;
myscore = PlayerPrefs.GetInt("MyScore");
lastScore = myscore;
}
function Update()
{
Go();
}
function OnGUI()
{
//GUI.skin = Skin;
if(canShow == true)
{
if(GUI.Button(Rect(Screen.width/2 - 200, Screen.height/2, 400, 100), "New Game"))
{
Application.LoadLevel(1);
}
if(GUI.Button(Rect(Screen.width/2 - 200, Screen.height/2 + 100, 400, 100), "Quit Game"))
{
Application.Quit();
}
GUI.Box(Rect(0, 0, 200, 150),"Welcome Back");
playerName = GUI.TextField(Rect(50, 25, 100, 25), playerName, 10);
PlayerPrefs.SetString("MyName", playerName);
GUI.Box(Rect(50, 75, 100, 25), "Last Score");
GUI.Box(Rect(50, 100, 100, 25), lastScore.ToString());
}
}
function Go()
{
yield WaitForSeconds(2);
canShow = true;
}
Pause
private var paused : boolean = false;
function Awake() { Screen.lockCursor = true; }
function Update() { if(Input.GetButtonDown("Pause")) { if(Screen.lockCursor == false) { Screen.lockCursor = true; Time.timeScale = 1.0;
MouseLook.sensitivityX = normalSensitivity;
MouseLook.sensitivityY = normalSensitivity;
paused = false;
}
else
{
Screen.lockCursor = false;
Time.timeScale = 0.0;
MouseLook.sensitivityX = 0;
MouseLook.sensitivityY = 0;
paused = true;
}
}
}
function OnGUI() { if(paused == true) { if(GUI.Button(Rect(Screen.width/2 - 200, Screen.height/2, 400, 100), "Main Menu")) { Application.LoadLevel(0); }
if(GUI.Button(Rect(Screen.width/2 - 200, Screen.height/2 + 100, 400, 100), "Quit Game"))
{
Application.Quit();
}
GUI.Box(Rect(Screen.width/2 - 100, Screen.height/2 - 100, 200, 50), "Paused");
}
}
You start Go() from Update (with no filter) so it's called every frame. $$anonymous$$aybe that resets your 'yield WaitFor...' so it never reaches the canShow
taking yield out worked but i found out another reason why it happened, thanks! :D
Answer by JSierraAKAMC · Feb 08, 2014 at 12:23 AM
if(paused == true)
{
if(GUI.Button(Rect(Screen.width/2 - 200, Screen.height/2, 400, 100), "Main Menu"))
{
Application.LoadLevel(0);
}
}
Needs to be
if(paused == true)
{
if(GUI.Button(Rect(Screen.width/2 - 200, Screen.height/2, 400, 100), "Main Menu"))
{
Time.timeScale = 1.0;
Application.LoadLevel(0);
}
}
or else it will remain "paused." Note that the time scale would still be 0 at the main menu.
oohh, thanks for the answer JSierraA$$anonymous$$A$$anonymous$$C :D it worked
You're welcome! If you have any questions, just ask! :D
Your answer
Follow this Question
Related Questions
help please: Level Changing Scipt 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
[Solved]Application.LoadLevel("Scene"); not working! 2 Answers
SceneManager.LoadSceneAsync causes lag spikes, how to make background loading less CPU heavy 1 Answer
Rotation stops when reload scene 1 Answer