How to make a button appear with a condition

I’ve a battle scene where two people (protagonist and enemy) fight. I’ve created a button (“Continue”) to go to another scene. The problem is that I want that button to appear only if enemy’s HP are < or = to 0.
Enemy’s script (HP part) (Oh, PV=HP and Enemigo=Enemy)

if (EnemigoPV <= 0)
{
GetComponent().SetTrigger(“isDying”);
GetComponent().Stop();
}
}
}
I want something like “If EnemyHP is < or = to 0, button Continue appears”.

Rather than using a bold font for code, you could use code-tags.

1 Like

Yep, use code tags. And you already have your condition check figured out, so within that, just call a manager script with a method to set the button gameobject active.

1 Like

Should I use something like:

buttonImage.gameObject.SetActive(false);

This will turn off the buttonImage gameObject. If buttonImage is not a gameobject variable, then yes, you can use that code to turn it off. Or true to turn it on.

If buttonImage is a gameobject variable, then you can take out the gameObject part as it already is a gameObject.

For some reason, the button appears just after I stop the scene (not when the enemy dies)…

Show us code and use code tags.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class Enemy : MonoBehaviour {
    public static float EnemigoPV = 80;
    public static float EnemigoMaxPV = 80;
    public Transform damTextObj2;
    public GameObject buttonImage;


    // Use this for initialization
    void Start () {
        AudioSource audio = GetComponent<AudioSource>();
        audio.Play();
        buttonImage.gameObject.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if ((Input.GetKeyDown("2")))
        {
            BattleFlow.currentDamage = 20;
            GetComponent<Animator>().SetTrigger("isAttacking");
            Instantiate(damTextObj2, new Vector3(59.4f, 1.806f, 65.32f), damTextObj2.rotation);
            BattleFlow.damageDisplay = "z";
        }
        if (BattleFlow.damageDisplay == "y")
        {
            EnemigoPV -= BattleFlow.currentDamage;
            Debug.Log (EnemigoPV);
            BattleFlow.damageDisplay = "n";
        }
            if (EnemigoPV <= 0)
        {
            GetComponent<Animator>().SetTrigger("isDying");
            GetComponent<AudioSource>().Stop();
            buttonImage.SetActive(true);
        }
    }
}

This is all enemy’s script.