Game Development Reference
In-Depth Information
Listing 8-3. GUIOptions.cs: A Class for the Main Menu
01 //--------------------------------------------------------------
02 //Class for menu functionality
03 using UnityEngine;
04 using System.Collections;
05 //--------------------------------------------------------------
06 public class GUIOptions : MonoBehaviour
07 {
08 //Sprite Renderer for menu
09 private SpriteRenderer SR = null;
10
11 //Collision objects for buttons
12 private BoxCollider[] Colliders = null;
13
14 //--------------------------------------------------------------
15 // Use this for initialization
16 void Start ()
17 {
18 //Get sprite renderer
19 SR = GetComponent<SpriteRenderer>();
20
21 //Get button colliders
22 Colliders = GetComponentsInChildren<BoxCollider>();
23
24 //Add listeners
25 GameManager.Notifications.AddListener(this, "ShowOptions");
26 GameManager.Notifications.AddListener(this, "HideOptions");
27
28 //Hide menu on startup
29 HideOptions(null);
30 }
31 //--------------------------------------------------------------
32 //Hide options event
33 public void HideOptions(Component Sender)
34 {
35 SetOptionsVisible(false);
36 }
37 //--------------------------------------------------------------
38 //Show options event
39 public void ShowOptions(Component Sender)
40 {
41 SetOptionsVisible();
42 }
43 //--------------------------------------------------------------
44 //Function to show/hide options
45 private void SetOptionsVisible(bool bShow = true)
46 {
47 //If enabling, then pause game - else resume
48 Time.timeScale = (bShow) ? 0.0f : 1.0f;
49
Search WWH ::




Custom Search