Hi, I’m making a health bar for bosses using a slider, and because those bosses have a large amount of HP, I want that bar have levels, something like this:
I don’t know what you have tried, or how you have implemented the way the damage is done. But you can create the health bar and sphere as a prefab, and put it in a folder named “Resources” then you can load both the health bar and the sphere runtime:
GameObject bar = Instantiate(Resources.Load("BAR", typeof(GameObject)));
GameObject sphere = Instantiate(Resources.Load("SPHERE", typeof(GameObject)));
Another approach could be to create a public reference to both the bar and sphere form your script as a GameObject, and load them runtime:
var bar = Instantiate(BAR) as GameObject;
var sphere = Instantiate(SPHERE) as GameObject;
And end up something like this:
public int Health;
public int Levels;
public GameObject BarHolder;
public GameObject Bar;
public GameObject Sphere;
// Update is called once per frame
void Update ()
{
if (Health <= 0)
{
Levels--;
}
if (Health >= 100)
{
Levels++;
}
}
private void RemoveLevel()
{
var bar = Instantiate(Bar) as GameObject;
// This moves the bar to the right place, of the GameObject is placed right
bar.transform.parent = BarHolder.transform;
Destroy(Sphere);
}
private void AddLevel()
{
// TODO same as Remove just
}
When you need to remove the gameobject just call Destory(BAR) or Destroy(SPHERE). Here’s some more reading: