Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Main Menu Code

Discussion in 'Works In Progress - Archive' started by JoshSavage, Aug 6, 2012.

?

Was this code useful?

Poll closed Aug 11, 2012.
  1. Yes!

    0 vote(s)
    0.0%
  2. Need more work!

    100.0%
  3. No!

    0 vote(s)
    0.0%
  1. JoshSavage

    JoshSavage

    Joined:
    May 25, 2012
    Posts:
    87
    Here is a basic main menu when paused it pauses the game but not audio or cam movement. Try it and see if its good.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PauseMenu : MonoBehaviour
    5. {
    6.     public GUISkin myskin;
    7.  
    8.     private Rect windowRect;
    9.     private bool paused = false , waited = true;
    10.  
    11.     private void Start()
    12.     {
    13.         windowRect = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200);
    14.     }
    15.  
    16.     private void waiting()
    17.     {
    18.         waited = true;
    19.     }
    20.  
    21.     private void Update()
    22.     {
    23.         if (waited)
    24.             if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.P))
    25.             {
    26.                 if (paused)
    27.                     paused = false;
    28.                 else
    29.                     paused = true;
    30.  
    31.                 waited = false;
    32.                 Invoke("waiting",0.3f);
    33.             }
    34.             if(paused)
    35.             Time.timeScale = 0;
    36.        
    37.         else
    38.             Time.timeScale = 1;
    39.        
    40.     }
    41.  
    42.     private void OnGUI()
    43.     {
    44.         if (paused)
    45.             windowRect = GUI.Window(0, windowRect, windowFunc, "Pause Menu");
    46.     }
    47.  
    48.     private void windowFunc(int id)
    49.     {
    50.         if (GUILayout.Button("Resume"))
    51.         {
    52.             paused = false;
    53.         }
    54.         if (GUILayout.Button("Options"))
    55.         {
    56.  
    57.         }
    58.         if (GUILayout.Button("Quit"))
    59.         {
    60.       //quit the game
    61.         Application.Quit();
    62.         }
    63.     }
    64. }
    65.  
     
unityunity