Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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