【Unity】オブジェクトのSetActive(false)に関して
他のスクリプトからSetActive(false);でオフにしたオブジェクトは、Awakeで呼び出されなくなる。
例えば、PlayerPrefsを呼び出したいのに、このブジェクトをオフにしたら、呼び出されない。
void Awake(){ if(instance ==null){ instance = this; } // Audio if (PlayerPrefs.GetInt ("MusicOnOff") == 0) { MusicBackground.isOn = false; } if (PlayerPrefs.GetInt ("MusicOnOff") == 1) { MusicBackground.isOn = true; } // ForceControl if (PlayerPrefs.GetInt ("ForceControl") == 0) { ForceButton.gameObject.GetComponent<RectTransform>().localPosition = DefaultPosForceButton; } if (PlayerPrefs.GetInt ("ForceControl") == 1) { ForceButton.gameObject.GetComponent<RectTransform>().localPosition = new Vector3(300f, -140f, 0f); } print("ForceControl = " + PlayerPrefs.GetInt ("ForceControl")); DefaultPosForceButton = ForceButton.transform.position; }
追記2015/5/12
オフにしたいコンポーネントだけ、enabledを用いて管理したほうが扱いやすいかも!
SetActiveかenabledかで非表示 | trick7