Skip to content

Instantly share code, notes, and snippets.

@SGTMcClain
Created December 12, 2020 22:43
Show Gist options
  • Save SGTMcClain/23bf3c2d7c7cc6993a14b71e03d28b40 to your computer and use it in GitHub Desktop.
Save SGTMcClain/23bf3c2d7c7cc6993a14b71e03d28b40 to your computer and use it in GitHub Desktop.
For use with buttons in unity to start and scenes
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