Skip to content

Instantly share code, notes, and snippets.

@maxbye3
Created December 1, 2015 08:40
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 maxbye3/03b1411a34462cdce432 to your computer and use it in GitHub Desktop.
Save maxbye3/03b1411a34462cdce432 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MenuSystem : MonoBehaviour {
public GameObject fadeInFadeOut;
public GameObject menuCanvas;
private Animator anim;
private Transform SubtitleTrue;
private Transform SubtitleFalse;
// Use this for initialization
void Start () {
Button startBtn = menuCanvas.transform.Find ("Main Menu").Find ("Start Game").GetComponent<Button> ();
Button optionBtn = menuCanvas.transform.Find ("Main Menu").Find ("Options").GetComponent<Button> ();
Button startOptionBtn = menuCanvas.transform.Find ("Options Menu").Find ("Start Game").GetComponent<Button> ();
GameObject MainMenu = GameObject.Find("Main Menu");
GameObject OptionsMenu = GameObject.Find("Options Menu");
OptionsMenu.SetActive (false);
anim = GetComponent<Animator> ();
/* START BUTTON */
startBtn.onClick.AddListener (() => {
Debug.Log ("Start Game");
// Remove the start button
MainMenu.SetActive(false);
// Start the game
anim.SetTrigger("StartGame");
});// start button
optionBtn.onClick.AddListener(() => {
Debug.Log ("Go to Options");
// Remove the start button
MainMenu.SetActive(false);
//Trigger Options Animation
anim.SetTrigger("GoToOptions");
menuCanvas.SetActive(false);
// Delay Options Menu For 3 Seconds
StartCoroutine(FadeInOptionsMenu());
// Options Fades In
OptionsMenu.SetActive (true);
});// options start
startOptionBtn.onClick.AddListener(() => {
Debug.Log ("Start Game");
// Remove the start button
MainMenu.SetActive(false);
//Trigger Options Animation
anim.Play("OptionsToStartGame",-1,0);
menuCanvas.SetActive(false);
});// start from options
/* OPTIONS MENU */
SubtitleTrue = OptionsMenu.transform.Find ("SubtitleTrue");
SubtitleFalse = OptionsMenu.transform.Find ("SubtitleFalse");
SubtitleFalse.GetComponent<Image>().enabled = false;
SubtitleTrue.GetComponent<Button> ().onClick.AddListener (() => {
// Start fading towards black.
Debug.Log ("Subtitles On");
SubtitleTrue.GetComponent<Image>().enabled = true;
SubtitleFalse.GetComponent<Image>().enabled = false;
});
SubtitleFalse.GetComponent<Button> ().onClick.AddListener (() => {
Debug.Log ("Subtitles Off");
SubtitleFalse.GetComponent<Image>().enabled = true;
SubtitleTrue.GetComponent<Image>().enabled = false;
});
}
IEnumerator FadeInOptionsMenu()
{
yield return new WaitForSeconds (3);
menuCanvas.SetActive (true);
menuCanvas.GetComponent<Animator>().Play ("FadeInMenu",-1,0);
}
public void FadeOut()
{
fadeInFadeOut.GetComponent<Animation>().Play ("FadeBlack");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment