I have create 10 Texture for FuelGauge.Name it on the Image. eg. FuelGauge0 shows Fuel 100% Full
So i am doing on a helicopter FuelGauge.I need to write a script that silimar to when helicopter
start flight,(Need Help 1st)my FuelGauge[starting 0]will slowly +1,to show an decreasing Fuel based on my texture
on the Image. (2nd)When helicopter stop,FuelGauge pause by not increasing by1. and(3rd) when Fuel= FuelGauge8 which show 20%
Show a warning or GUI.Text “20% left”. and (4) when no fuel which FuelGauge10 shows 0% ,helicopter will fall and explode.
I really in need help for this,For those who knows how to do this pls help me.pls
Currently i have put it my texture:
var FuelGauge : Texture;
function OnGUI () {
GUI.Label( Rect( 5, 70, 100, 100 ), FuelGauge[0] ); //needs to be edit
Make sure you actually create the timer variable… Here is the edited script with the declared variable timer:
var FuelGauge : Texture[];
var myTextureHeight : float;
var myTextureWidth : float;
var timer : float = 0;
function OnGUI(){
if(timer < 20)
{
Debug.Log("Full fuel");
}
if(timer < 40 && timer > 20)
{
Debug.Log("20 sec passed - fuel is lower");
}
if(timer < 60 && timer > 40)
{
Debug.Log("40 sec passed - fuel is lower");
}
}
function Update () {
timer += Time.deltaTime;
}
Check your debug console and it should say Full fuel and then after 20 sec say 20 sec passed fuel lower… You can change these messages with the actual GUI later but this is good for clearing errors.
Well, I suppose you will want to decrease the fuel over time so I would suggest using a timer to check how much time has passed and then set the texture accordingly. Is your script that you posted working? If it is then I’m surprised that you can use GUI.Label to display a texture You could probably also use GUI.DrawTexture like this:
var FuelGauge : Texture[];
var myTextureHeight : float;
var myTextureWidth : float;
function OnGUI(){
GUI.DrawTexture(Rect( Screen.width * 0.5, Screen.height * 0.5, myTextureWidth, myTextureHeight), FuelGauge[0]);
}
If you create a simple timer then you can just always check with if statements:
Hope this helps and to create the timer just create a float and you can use Time.deltaTime or Time.time - You can just search it though, there are plenty of threads on that topic.