Created
July 17, 2017 16:36
-
-
Save JonathanYin/66e00a0eea3e93e0fb57219a2e3b2d7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
using UnityEngine.SceneManagement; | |
public class SceneLoader : MonoBehaviour | |
{ | |
private bool loadScene = false; | |
public GUIElement gui; | |
public GUIText myGUIText; | |
public GUIText myGUIText1; | |
[SerializeField] | |
public int scene; | |
[SerializeField] | |
public Text loadingText; | |
// Updates once per frame | |
void Update() | |
{ | |
} | |
// The coroutine runs on its own at the same time as Update() and takes an integer indicating which scene to load. | |
IEnumerator LoadNewScene() | |
{ | |
// This line waits for 3 seconds before executing the next line in the coroutine. | |
// This line is only necessary for this demo. The scenes are so simple that they load too fast to read the "Loading..." text. | |
yield return new WaitForSeconds(3); | |
// Start an asynchronous operation to load the scene that was passed to the LoadNewScene coroutine. | |
AsyncOperation async = SceneManager.LoadSceneAsync(scene); | |
// While the asynchronous operation to load the new scene is not yet complete, continue waiting until it's done. | |
while (!async.isDone) | |
{ | |
yield return null; | |
} | |
} | |
void OnGUI() | |
{ | |
if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 125, 100, 40), "Play")) | |
{ | |
SceneManager.LoadScene(1); | |
//Application.LoadLevel(0); | |
} | |
if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 175, 100, 40), "Quit")) | |
{ | |
Application.Quit(); | |
} | |
if (GUI.Button(new Rect(Screen.width / 2 + 440, Screen.height / 2 - 325, 100, 40), "Instructable")) | |
{ | |
Application.OpenURL("http://www.instructables.com/id/Make-A-2D-Infinite-Runner-with-Unity/"); | |
} | |
if (GUI.Button(new Rect(Screen.width / 2 + 440, Screen.height / 2 - 255, 180, 40), "Download the original game!")) | |
{ | |
Application.OpenURL("https://www.dropbox.com/s/w2a1vj83kg3fpjl/Game1.zip?dl=0"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script creates the loading screen in my game. It includes several buttons that allow the player to play the game or quit. In addition, there are buttons that lead to the Instructable from which I was able to create my first game, as well as a link to the download for my first game.