I have been working on this game over screen but when it came to enabling it when dead a problem came there were no errors in fact it seemed to be fine because I could Send a statement to the console when dead and it would work but the enabling of the UI would not. I would love some help with this if you can.
_
Code:
_
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Damage : MonoBehaviour
{
public int maxHealth = 5;
public int currentHealth;
public int DamageCount;
public Image GameOver;
public HealthBar healthBar;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
healthBar.SetMaxHealth(maxHealth);
DamageCount = 0;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
TakeDamage(1);
DamageCount += 1;
}
if (DamageCount == 5)
{
GameOver.enabled = true;
Debug.Log("Enabled");
}
}
void TakeDamage(int damage)
{
currentHealth -= damage;
healthBar.SetHealth(currentHealth);
}
}
_
I found the answer to the problem here is what I changed so basically Instead of
GameOver.enabled = true; use
GameOver.gameObject.SetActive(true);
if the image is a component of a gameobject.