So I was watching one of burgzergarcade’s videos where I found out how to make a healthbar. Really helped but I wanna know how to add my own gui texture to it. Can someone explain to me how, checked the references but got confused
Thanks in advance!
using UnityEngine;
using System.Collections;
public class PlayerHealth1 : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 4;
}
// Update is called once per frame
void Update () {
AdjustCurrentHealth(0);
}
void OnGUI(){
GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AdjustCurrentHealth(int adj){
curHealth += adj;
if(curHealth < 1)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 4) * (curHealth / (float)maxHealth);
}
}
A pic of the gui texture