Quantcast
Channel: Latest Questions by werseburg
Viewing all articles
Browse latest Browse all 14

Screen.width ~ HealthBar problem - C#

$
0
0
I've spent over an hour setting up the GUI.Box in C# for a "healthbar" and even though the code compiles, it seems the logic of the script seems to be correct, the "healthbar" wont show up when playtested and the float value healthBarLength shows up as 0 inside the unity editor. I wanted it to work the following way: GUI.Box is 1/2 of the screenwidth, it becomes shorter when you lose health... It shows nothing when you drag. Also, where should I place the Float healthBarLength for the script to work, if I put it just next to public int curHealth = 100; public float healthBarLength = (curHealth / maxHealth); It wont compile at all ;/ >>> using UnityEngine; using System.Collections; public class healthbar : MonoBehaviour { public int maxHealth = 100; public int curHealth = 100; public float healthBarLength; // Use this for initialization void Start () { OnGui(); } // Update is called once per frame void Update () { } void OnGui() { healthBarLength = ((Screen.width / 2) / (curHealth / maxHealth)); GUI.Box(new Rect(100, 100, healthBarLength, 20), curHealth + "/" + maxHealth); } }

Viewing all articles
Browse latest Browse all 14

Trending Articles



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