Created
December 12, 2020 22:43
-
-
Save SGTMcClain/23bf3c2d7c7cc6993a14b71e03d28b40 to your computer and use it in GitHub Desktop.
For use with buttons in unity to start and scenes
This file contains hidden or 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
using UnityEngine.UI; | |
public class StartGame : MonoBehaviour | |
{ | |
public Button startButton; | |
public Button mainMenuButton; | |
private void Start() | |
{ | |
//Calls the TaskOnClick/TaskWithParameters/ButtonClicked method when you click the Button | |
startButton.onClick.AddListener(RestartGame); | |
mainMenuButton.onClick.AddListener(MainMenu); | |
} | |
public void RestartGame() | |
{ | |
SceneManager.LoadScene("SampleScene"); | |
PlayerPrefs.DeleteAll(); | |
} | |
public void MainMenu() | |
{ | |
SceneManager.LoadScene("Start"); | |
PlayerPrefs.DeleteAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment