I'm generally new to C#, so bear with me please.
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth=100;
public int curHealth=100;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);
}
void OnGUI() {
GUI.Box (new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj) {
curHealth += adj;
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
}
I'm getting the error:
DivideByZeroException: Division by zero
PlayerHealth.OnGUI () (at Assets/Scripts/PlayerHealth.cs:19)
What am I doing wrong?
↧