Hello i am trying to reduce healt and mana while pressing ‘H’. I know that for each event in GUI i need to use Event.current instead of Input.GetKeyDown since this is GUI event.
Here is the code, when i am pressing H nothing is happening it should reduce hp and sp but it does not. Anyone could tell me why is that please ?
#pragma strict
var curHp : float = 100.0;
var maxHp : float = 100.0;
var curSp : float = 50.0;
var maxSp : float = 50.0;
var hpBarTexture : Texture2D;
var spBarTexture : Texture2D;
var hpBarlength : float;
var percentOfHp : float;
var spBarLength : float;
var percentOfSp : float;
private var _hpSpWindowRect : Rect = new Rect(10,Screen.height / 2 + 150,190,70);
private var _hpSpWindowID : int = 1;
function OnGUI () {
var e = Event.current;
if (e.type == EventType.KeyDown && e.keyCode == KeyCode.H)
ReduceHelathAndMana();
_hpSpWindowRect = GUI.Window(_hpSpWindowID, _hpSpWindowRect, HpSpWindow, "Health points / Spell points");
}
function ReduceHelathAndMana() {
percentOfHp = curHp/maxHp;
hpBarlength = percentOfHp*100;
percentOfSp = curSp/maxSp;
spBarLength = percentOfSp*100;
}
function HpSpWindow (_hpSpWindowID) {
if (curHp > 0)
{
GUI.Box (new Rect (20,20,150,20),hpBarTexture);
}
if (curSp > 0)
{
GUI.Box (new Rect (20,40,150,20),spBarTexture);
}
GUI.DragWindow();
}