Skip to content

Instantly share code, notes, and snippets.

@SenpaiRar
Created May 15, 2019 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SenpaiRar/0641c9fa7c816c6911672910950ca848 to your computer and use it in GitHub Desktop.
Save SenpaiRar/0641c9fa7c816c6911672910950ca848 to your computer and use it in GitHub Desktop.
The script for the Main Menu.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//This package contains the commands for loading different scenes
using UnityEngine.SceneManagement;
public class MainMenuScript : MonoBehaviour
{
//This function starts the game by loading the scene with all our gameobjects
public void StartGame(){
StartCoroutine(StartLoadingScene());
}
//This function quiets the game by calling Application.Quit()
public void QuitGame(){
Application.Quit();
}
//This is a coroutine. While how it works is somewhat vague, what it does is pauses the game until the scene is done loading
//This makes performance in terms of computing much easier
IEnumerator StartLoadingScene(){
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("TestScene");
while(!asyncLoad.isDone){
yield return null;
}
StopCoroutine(StartLoadingScene());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment