I am trying to get a Moba styled health bar, as in if I have 1000hp there should be 9 lines
like this: 100hp|100hp|100hp|100hp|100hp|100hp|100hp|100hp|100hp|100hp
And if I have 2000hp I should have 19 lines, and so on and so forth.
Here is my code, I am having trouble:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealth : MonoBehaviour {
public int MaxHealth = 100;
public int CurrentHealth = 0;
public int BarWidth = 50;
void Awake() {
CurrentHealth = MaxHealth;
}
void Update() {
float pixelsPerHP = (float)BarWidth / MaxHealth;//~0.6f
int everyHundredHPLineOffset = Mathf.RoundToInt(pixelsPerHP * 100);//~60
int numberOfLines = Mathf.RoundToInt((float)MaxHealth / 100);
for (int i = 1; i < numberOfLines + 1; i++) {
int offset_current = i * everyHundredHPLineOffset;
//Draw line using offset_current
}
}
}
But I don’t know how to draw the line.
Does anyone know? Please help me. Thanks!