Search Unity

Unity UI Options Menu

Discussion in 'UGUI & TextMesh Pro' started by wishingchain, Jun 6, 2018.

  1. wishingchain

    wishingchain

    Joined:
    Oct 5, 2016
    Posts:
    25
    Hi, I was wondering how to make a options menu that you can access at anytime that can change the resolution/volume and other stuff from in game without resetting your position. Is it also possible to save your current progress in the game? I am using this script right now that just loads a new scene to play the game. I removed the Options void as I could not get it working. Any help would be appreciated, thanks.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class MainMenu : MonoBehaviour {
    7.  
    8.  
    9.     public void PlayGame()
    10.     {
    11.         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex +1);
    12.     }
    13.  
    14.     public void Options()
    15.     {
    16.         SceneManager.LoadScene(2);
    17.     }
    18.  
    19.     public void Optionsback()
    20.     {
    21.         SceneManager.LoadScene(0);
    22.     }
    23.  
    24.  
    25.     public void QuitGame()
    26.     {
    27.         Debug.Log("Quitting...");
    28.         Application.Quit();
    29.     }
    30.  
    31. }
    32.  
     
  2. hjohnsen

    hjohnsen

    Joined:
    Feb 4, 2018
    Posts:
    67
    For your option, search for "pause menu" in the script sub forum I think or on google. You do not need to load another scene to do that, you can have some hidden canvas. For example :


    Code (CSharp):
    1.     public static void HideUI(GameObject gameObject)
    2.     {
    3.         HideUI( gameObject.GetComponent<CanvasGroup>() );
    4.     }
    5.  
    6.     public static void HideUI(CanvasGroup cg)
    7.     {
    8.         cg.interactable = false;
    9.         cg.alpha = 0;
    10.     }
    11.  
    12.     public static void ShowUI(GameObject gameObject)
    13.     {
    14.         ShowUI( gameObject.GetComponent<CanvasGroup>() );
    15.     }
    16.  
    17.     public static void ShowUI(CanvasGroup cg)
    18.     {
    19.         cg.interactable = true;
    20.         cg.alpha = 1.0f;
    21.     }
    22.  
    23.  
    For state saving you should search the script forum too.
     
    wishingchain likes this.
  3. wishingchain

    wishingchain

    Joined:
    Oct 5, 2016
    Posts:
    25
    Thanks, I just did this and it works perfectly