Hi ya, I’m quite new to coding and game building.
I have created a simple UI, it shows in the test screen, but when I hit play to test it with the rest of the game it completely disappears ??
It disappears from the hierarchy and cant work out why ?
the scaling is set with the screen and resolution size is correct and it doesn’t appear to be hidden in any way that I could find ? and its on its correct layer ?
any help would be greatly appreciated
if it goes from heirachy, then somethings destroying it… if it was in the heirachy, then it wouid point to anchors
1 Like
Interesting, something is destroying it then ? Any idea how i would go about finding what is destroying it ?
I don’t know if this will help but this is the code I’m using
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class CanvasManager : MonoBehaviour
{
public TextMeshProUGUI health;
public TextMeshProUGUI armor;
public TextMeshProUGUI ammo;
public Image healthIndicator;
public Sprite health1; //healthy 100%
public Sprite health2;
public Sprite health3;
public Sprite health4;
public Sprite health5; // dead 0%
public GameObject redKey;
public GameObject blueKey;
public GameObject yellowKey;
private static CanvasManager _instance;
public static CanvasManager Instance
{
get { return _instance; }
}
private void Awake()
{
if (_instance == null && _instance != this)
{
Destroy(this.gameObject);
}
else
{
_instance = this;
}
}
// methods to update our ui
public void UpdateHealth(int healthValue)
{
health.text = healthValue.ToString() + “%”;
UpdateHealthIndicator(healthValue);
}
public void UpdateArmor(int armorValue)
{
armor.text = armorValue.ToString() + “%”;
}
public void UpdateAmmo(int ammoValue)
{
ammo.text = ammoValue.ToString();
}
public void UpdateHealthIndicator(int healthValue)
{
if (healthValue >= 75)
{
healthIndicator.sprite = health1; // healthy face
}
if(healthValue <75 && healthValue >= 50)
{
healthIndicator.sprite = health2;
}
if(healthValue <50 && healthValue >= 25)
{
healthIndicator.sprite = health3;
}
if(healthValue <25 && healthValue > 0)
{
healthIndicator.sprite = health4;
}
if(healthValue <= 0)
{
healthIndicator.sprite = health5;
}
}
public void UpdateKeys(string keyColor)
{
if(keyColor == “red”)
{
redKey.SetActive(true);
}
if (keyColor == “blue”)
{
blueKey.SetActive(true);
}
if (keyColor == “yellow”)
{
yellowKey.SetActive(true);
}
}
public void ClearKeys()
{
redKey.SetActive(false);
blueKey.SetActive(false);
yellowKey.SetActive(false);
}
}
if (_instance == null && _instance != this)
should have been
if (_instance != null && _instance != this)
1 Like