這裏我使用SetActive(true)來啓用我的gameObject,但它不起作用。我嘗試過使用各種函數和對象,可以在代碼中看到我的gameObj。但沒有任何工作。雖然當我設置setActive(false)時,它可以工作,但這不是setActive(true)的事件。我不知道原因。任何人都可以幫助我嗎?順便說一句,我使用Unity 4.3.4版本。Unity 2D SetActive()不起作用
if (paddle.life == 1) {
GameObject life_2 = GameObject.Find ("life2");
GameObject lost = GameObject.Find("lostlife");
life_2.SetActive (false);
lost.SetActive(true);
//lost.active = true;
//lost.renderer.enabled = true;(why null ref)
//after some secs disable the message
//Destroy(lost, 4);
}
定義 「不工作」 - 什麼是實際發生的? –
嘗試調試您的代碼。使用斷點可能是。它必須是你的代碼邏輯有問題。 –
調用set active只會將localActive標誌設置爲您在該函數中給出的值。如果父遊戲對象被禁用,則不會有任何孩子變爲活動的 –