[Unity]Show Hide GameObject

Unity Show and Hide GameObject

Unity 展示與隱藏GameObject程式碼:

using UnityEngine;
using System.Collections;

public class ShowHide : MonoBehaviour {

        
        private GameObject party;
        // Use this for initialization
        void Start () {
        party =  GameObject.Find("Button (5)");
        }
        
        // Update is called once per frame
        void OnGUI () {
            if(GUI.Button (new Rect(Screen.width / 2 - 50, Screen.height /  2 + 20, 200, 75), "Show Hat"))
            {
                party.SetActive(true);
                
            }
            if(GUI.Button (new Rect(Screen.width / 2 - 30, Screen.height /  2, 100, 50), "Main Menu"))
            {
            
            party.SetActive(false);//Application.LoadLevel(0);
            }
        }
    }