Defeat a enemy and victory message to appear, with trouble

I tried to use the Set Active to destroy the game object and the victory message is true, but I can’t do it. Someone help me?

This is my code:

obs: Read my code number 71

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

public class PlayerContoller : MonoBehaviour , IInteractable
{
    float frente;
    float re;
    float girar;

    [Header("VIDA")]
    public Image playerHealthFill;
    public Image playerHealthFillRed;
    public Image loseHd;
    public float playerHealthMax = 100f;
    public float playerHealthCurrent = 0f;

    [Header("BALA")]
    public GameObject bullet;
    public GameObject spawnBullet;

    // Start is called before the first frame update
    void Start()
    {
        frente = 10;
        re = 5;
        girar = 60;

        HealthManager(playerHealthMax);
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.W))
        {
            transform.Translate(0, 0, (frente * Time.deltaTime));
        }

        if (Input.GetKey(KeyCode.S))
        {
            transform.Translate(0, 0, (-re * Time.deltaTime));
        }

        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(0, (-girar * Time.deltaTime), 0);
        }

        if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(0, (girar * Time.deltaTime), 0);
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            Shooting();
        }

    }

    private void OnCollisionEnter(Collision other)
    {
        if(other.gameObject.tag == "Enemy")
        {
            Debug.LogWarning("perdeu");
        }
    }

    void HealthManager(float value)
    {
        Debug.LogWarning("HealthManager");
        Debug.LogWarning("value" + value);

        playerHealthCurrent += value;
        playerHealthFill.fillAmount = playerHealthCurrent / 100;

        if(playerHealthFill.fillAmount == 0)
        {
            Destroy(this.gameObject);
            playerHealthFillRed.gameObject.SetActive(false);
            loseHd.gameObject.SetActive(true);
        }

      

    }

    void Shooting()
    {
        Instantiate(bullet, spawnBullet.transform.position, spawnBullet.transform.rotation);
    }

 

    public void Interact(float value)
    {
        Debug.LogWarning("HealthManager");
        Debug.LogWarning("value" + value);

        playerHealthCurrent += value;
        playerHealthFill.fillAmount = playerHealthCurrent / 100;

        HealthManager(-10);
    }
}

My suggestion is to Debug.Log your values. What value are you getting for playerHealthCurrent and playerHealthFill.fillAmount and keep checking if you ever hit 0 when you expect to.

It hits, but when using the loseHd.Set Active code, it doesn’t work due to the Destroy Game Object

 loseHd.gameObject.SetActive(true);

My only trouble is this code:

loseHd.gameObject.SetActive(true);

public Image loseHd;

Nothing above is helpful to the troubleshooting process.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand compiler and other errors and even fix them yourself:

https://discussions.unity.com/t/824586/8

If you want to be able to understand what is ACTUALLY happening in your code, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.

I would say, you could just switch the order of the destroy so it’s the last call made in the if statement. Not sure if that’s enough to get you what you want.