This is my current code in Javascript:
Code: Select all
var availableLevels : String[];
var PlayerObject : GameObject;
var minicam : GameObject;
var maincam : GameObject;
var playerSpawn : String;
var windowWidth : int = 200;
var windowHeight : int = 200;
private var showMenu : boolean = false;
var playerController : SpaceFlight;
function OnMouseDown () {
showMenu = true;
playerController.moving();
}
function OnGUI () {
if (showMenu) {
GUI.Window(0,
Rect((Screen.width / 2) - (windowWidth / 2),
(Screen.height / 2) - (windowHeight / 2),
windowWidth,
windowHeight),
LevelSelect,
"3-1 Phase Gate"); //Creates a window with ID 0 in the center of the screen using the function LevelSelect with the title, "Select a level!"
}
}
function LevelSelect (id : int) {
for (var levelName : String in availableLevels) {
if (GUILayout.Button(levelName)) {
DontDestroyOnLoad (PlayerObject);
DontDestroyOnLoad (minicam);
DontDestroyOnLoad (maincam);
Application.LoadLevel(levelName);
spawnPoint = GameObject.FindWithTag(playerSpawn);
}
}
if (GUILayout.Button("Cancel")) { //Gives the player the opportunity to back out of the menu.
showMenu = false;
}
}