Fundaments of Game Design Unity Scenes and GUI Buttons Richard Gesick
Objectives Using multiple scenes in a game Using GUI buttons and labels
Scenes In your scripts, scenes are controlled thru the UnityEngine.SceneManagement library so you need to include it as a using statement. Adding scenes to a Unity game is easy. After saving your current scene, just select file new scene and start its development. To be able to switch scenes during game play, the scenes must be in the scenes in build directory under file build settings
Scenes in Build
Notes about scenes in build Each scene has a name and a number and can be called either way. While numbers are easy to sequence, recommend you use names. If a scene is deleted, the remaining numbers adjust for the missing number but it does not get refactored in your code.
Control display function void OnGUI() { if(GUI.Button(new Rect(left,top,width,ht),"Play Game")) SceneManager.LoadScene("mainScene"); } if(GUI.Button(new Rect(left,top+75,width,ht),"Directions")) SceneManager.LoadScene("dirScene");
A health bar with a GUI box public float currentHP = 100; public float maxHP = 100; public float currentBarLength; public float maxBarLength = 100; . . . currentBarLength = currentHP * maxBarLength / maxHP; GUI.Box(new Rect(Screen.width/2 - 20, Screen.height/2 + 300, currentBarLength, 25f), "");