So I’m using GUI Manager to manage my in-game GUI elements. What a great resource! Thanks besuser!
I have a UI gauge that goes up when the laser gets to hot, and then goes down when it cools. Seems easy enough. I’m using GUIQuadObj.Height to raise and lower the size of the graphics (then I have to use GUIQuadObj.Location to move it back down to its proper position). Moving the stuff works fine, but I’m having trouble figuring out the math to determine how full/empty the meter should be at any given point.
I’m sure it’s simple, but math really was my weak subject in school. anyone got any tips to get me started?
sounds what I need, but I’m still having trouble wrapping my brain around it. Can you give me some cde examples where inverselerp is used?
Perhaps this? It uses Lerp in addition to InverseLerp. It’s about setting fog density based on the player’s height, but you could use the exact same principle to set a gauge height based on a heat value.
–Eric
Got it working!
As it turned out, I didn’t need to use InverseLerp at all. I looked through the Unity FPS tutorial (which has a health meter) and managed to figure it out based on that code.
Here’s what I’m doing:
function UpdateHeat(){
// calculate the fraction of how much heat there is left
var heatFraction : float = (currentGunHeat / maxGunHeat);
// update the GUI
var GUIHeatObject = thermometerFill.gameObject.GetComponentsInChildren (GUIQuadObj);
for (var GUIHeat : GUIQuadObj in GUIHeatObject) {
// adjust heat height based on that fraction
GUIHeat.Height = (maxHeatHeight * heatFraction);
// move the object down based on its height
// because it starts higher than it should, we need an offset
var heatLocation = maxHeatLocationY - (thermoFillMoveValue * GUIHeat.Height) + heatOffset;
GUIHeat.Location = Vector2(maxHeatLocationX, heatLocation);
}
}
works great! Thanks for your help Eric!