1
我會如何讓玩家死掉一個按鈕後出現?讓玩家死後出現一個按鈕 - Unity3D 4.6 GUI C#
我已經有重新啓動級別編碼,並且我在屏幕上使用該代碼的按鈕。我該如何做到這一點,因爲這個按鈕沒有顯示,並且只有在玩家死了之後才能正常工作?
迴應如下。
public GameObject RESTART_BUTTON;
bool isDead = false;
void Update()
{
if (isDead == true)
{
RESTART_BUTTON.gameObject.SetActive(true);
Debug.Log("Do show game object");
}
}
void Start()
{
if (isDead == false)
{
RESTART_BUTTON.gameObject.SetActive(false);
Debug.Log("Do Not show game object");
}
}
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log(collision.gameObject.tag);
if (collision.gameObject.tag == "Death")
{
isDead = true;
Debug.Log("isDead_true");
}
}
這裏是我的控制檯輸出http://i.imgur.com/XFnOhHh.png
public void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log(collision.gameObject.tag);
if (collision.gameObject.tag == "Death")
{
//Destroy(gameObject);
isDead = true;
} // end if including tag collision
} // End OnCollisionEnter
IEnumerator isDeath()
{
if (isDead == true)
{
_animator.Play(Animator.StringToHash("Jump"));
;
yield return new WaitForSeconds(2);
Destroy(gameObject); //this will wait 5 seconds
} // end if including boolean isDead
}
UnassignedReferenceException:OnDeathGUI的變量RESTART_BUTTON尚未分配。 您可能需要在檢查器中分配OnDeathGUI腳本的RESTART_BUTTON變量。 OnDeathGUI.Start()(在資產/腳本/ OnDeathGUI.cs:10) 是我收到的錯誤... – user3708761 2015-04-06 07:04:03
您將不得不將檢查器中的重新啓動按鈕分配給YourButton變量。 – Archit 2015-04-06 07:06:02
嗯,它絕對不會在播放時顯示,但即使當isdead布爾值爲true時,它也不會顯示出來。我將用我的代碼編輯主帖子。 – user3708761 2015-04-06 07:31:47