Making a button appear after player death - Unity3D 4.6 GUI C#

后端 未结 1 1802
慢半拍i
慢半拍i 2021-01-23 19:52

How would I make it so once the player dies a button appears?

I already have the restart level coded, and I have the button on screen that utilizes that code. How do I m

相关标签:
1条回答
  • 2021-01-23 20:39
    public GameObject YourButton;
    

    keep the button inactive while the player is alive. Once he is dead, execute the following code.

    YourButton.gameObject.setActive(true);
    

    This would activate the button on the screen.

    Add this code in void Update() and change the code in void start() and collision to:

     // // Update is called once per frame
     void Update () {
     if(isDead == true){
        RESTART_BUTTON.gameObject.SetActive(true);
        }
    }
    
    void Start () {
        if(isDead == false){
        RESTART_BUTTON.gameObject.SetActive(false);
        }
     }
    
    public void OnCollisionEnter2D(Collision2D collision){
    Debug.Log(collision.gameObject.tag);
    if(collision.gameObject.tag == "Death"){
        isDead = true;
    } 
    }
    

    That should do the needful.

    0 讨论(0)
提交回复
热议问题