Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Division By Zero Error? C# Code Help

$
0
0
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?

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>