スポンサーリンク
ボタンやテキストなど、すでにゲットコンポーネントしているゲームオブジェクトの表示、非表示について、実は簡単に表示・非表示が切り替えられることを知りました。
using UnityEngine; using UnityEngine.UI; using System.Collections; public class Sample : MonoBehaviour { private Button aButton; void Awake() { // ボタンをゲットコンポーネント aButton = GameObject.Find("Button_PlayGame").GetComponent<Button>(); } // Use this for initialization void Start () { // 取得したコンポーネントを持つゲームオブジェクトのSetActive() aButton.gameObject.SetActive(false); } }
取得しているコンポーネント.gameObject.SetActive(true/false);
今まではわざわざそれ用の変数を用意していた自分にとってはかなり朗報でした!