Hello, I think this is simple but my headeach does not let me see the answer hahaha. Ok I made this to consume the energy bar while the player press Shift. But if the player press Shift the energy bar gets 0, starts to grow to the oposite direction, all i want is to stop this “if effect” to the GUI when its width is = 0.
#pragma strict
var GUIEnergy : GUITexture;
function Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
GUIEnergy.pixelInset.width -= 0.3;
}
}
Either : check if the pixelInset is greater than zero plus 0.3 before removing 0.3
Or : after removing 0.3, check if pixelInset is below zero. If so, make pixelInset zero
Either :
#pragma strict
var GUIEnergy : GUITexture;
function Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
if ( GUIEnergy.pixelInset.width >= 0.3 )
{
GUIEnergy.pixelInset.width -= 0.3;
}
}
}
Or :
#pragma strict
var GUIEnergy : GUITexture;
function Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
GUIEnergy.pixelInset.width -= 0.3;
if ( GUIEnergy.pixelInset.width < 0 )
{
GUIEnergy.pixelInset.width = 0;
}
}
}