- Home /
Fuel Script error
" />
Hi below is a working script.This script works in displaying a timer displaying 00:00:00>to 00:00:01 in Hour,Min,Second.
now is runs for every 1mins my GUI.Label( Rect( 5, 25, 100, 100 ), FuelGauge[displayMinutes * 1] ); my FuelGauge[will +1],
So nows the point.i only have FuelGauge0-10,so after 10mins my fuelGauge texture gone.how am i suppose to make it stay at -------- FuelGauge[10] and show a text "no Fuel" can any1 help Thx very Much ...
When you looking at the image below,i wanted when the fuel reach 0 it will hold there,but not disspear . or any1 have better idea for making fuel run just like a car,means when start fuel drop and car stop fuel pause and when no fuel i want it explode
private var startTime;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
private var displayHours : int;
var countDownSeconds : int;
var FuelGauge : Texture[];
function Awake() {
startTime = Time.time;
}
function OnGUI () {
//make sure that your time is based on when this script was first called
//instead of when your game started
var guiTime = Time.time + startTime;
restSeconds = countDownSeconds + (guiTime);
GUI.Label( Rect( 5, 25, 100, 100 ), FuelGauge[displaySeconds * 1] );
//display the timer
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
displayHours = roundedRestSeconds / 60;
text = String.Format ("{0:00}:{0:00}:{1:00}", displayMinutes, displaySeconds);
GUI.Label (Rect (400, 25, 100, 30), text);
}
function Update(){
if ( displaySeconds > 10 ) {
GUI.Label( Rect( 5, 25, 100, 100 ), FuelGauge[10]);
GUI.Text(Rect(5, 50,100,100),"No Fuel");
}
else if ( displaySeconds < 0 ) {
displaySeconds = 0;
}
}
You've posted here a few times, so I think it's time you started formatting your posts properly. Can you please add four spaces to the beginning of every line? To speed things up, you can select everything and use the '10101' button.
thx for editing,i will do next time,but why leave four spaces for??
The four spaces indicate that a line is supposed to be 'code'. It's just the formatting convention on the site.
syclamoth,why under some of my question ,you didnt reply,is you dont understand what i write or no idea how to do it?
Answer by wenhua · Jan 17, 2012 at 09:45 AM
Thx to merry christmas
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;
}
somethings silimar for it to work, just use different timer. if some 1 know how to edit the top script, you are free to do so. Thx
Answer by luozitian · Jan 14, 2012 at 08:24 AM
Please note All GUI can only put into OnGUI() fuction otherwise it does work,put all below your code to OnGUI function, and you can add condition for toggle to display what you want
if ( displaySeconds > 10 ) {
GUI.Label( Rect( 5, 25, 100, 100 ), FuelGauge[10]);
}
else if ( displaySeconds < 0 ) {
displaySeconds = 0;
GUI.Text(Rect(5, 50,100,100),"No Fuel");
}
But the code got error,i doesnt know how to solve.like i want it to be when FuelGaue is=10 .it will stay at FuelGauge10, not with timer and texture of FuelGauge all gone from the display scene. i need some1 to $$anonymous$$ch me or help me pls. But also how to pause when helicopter stop....thx
Your answer
Follow this Question
Related Questions
Explosive like in COD 4? 1 Answer
Timer activates script 1 Answer
Deactivating a power up script after a certain amount of time 1 Answer
Usage timer/weapon cooldown... 3 Answers
Audio after Audio Loop 1 Answer