Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by wenhua · Jan 13, 2012 at 04:00 AM · timer

Fuel Script error

alt text" />

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;

 }

}

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Jan 13, 2012 at 04:16 AM 0
Share

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.

avatar image Rod-Green · Jan 13, 2012 at 04:49 AM 0
Share

i just did it for him.. i'll undo it so he can learn.

avatar image wenhua · Jan 13, 2012 at 06:02 AM 0
Share

thx for editing,i will do next time,but why leave four spaces for??

avatar image syclamoth · Jan 13, 2012 at 06:10 AM 0
Share

The four spaces indicate that a line is supposed to be 'code'. It's just the formatting convention on the site.

avatar image wenhua · Jan 13, 2012 at 06:14 AM 1
Share

syclamoth,why under some of my question ,you didnt reply,is you dont understand what i write or no idea how to do it?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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");

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wenhua · Jan 14, 2012 at 03:19 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges