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);
}
}