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 Nercoe · Sep 27, 2012 at 07:33 PM · guicolortimechange

Change colour of int when reaches specific number

Hey guys, just wondering if you could help me out. I'm a bit of a freshy with JavaScript but I'm learning a lot quite quickly from you guys :) What I am trying to do is change the colour of my integer when it reaches 10 (it starts on 100 and ticks down at a set rate). When the int reaches 10 I would like it to change to red from yellow. I already have the text printed on the screen and have tried several ways of implementing it but to no avail. Just wondering if you guys can show me the ropes with GUI :) Here's the code!

 var speed : float = 3.0;
 var rotateSpeed : float = 3.0;
 var bulletPrefab:Transform;
 var shotDelay = 2;
 var status1 = "Loaded";
 var fuel : float = 100.0;
 var fuelDeduct = 2.0;
 var percentage = "%";
 var style : GUIStyle;
 
    function Start () {
 
     while (true) {
         while (!Input.GetButtonDown("Jump")) yield;
        bullet = Instantiate(bulletPrefab, GameObject.Find("SpawnPoint").transform.position, transform.rotation);
          bullet.tag = "bulletShot";
          status1 = "Reloading";
          bullet.rigidbody.AddForce(transform.forward * 5000);
         yield WaitForSeconds(shotDelay);
         status1 = "Loaded";
     }
 }
 
 function Update ()
 {
     var controller : CharacterController = GetComponent(CharacterController);
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
     var forward : Vector3 = transform.TransformDirection(Vector3.forward); var curSpeed : float = speed * Input.GetAxis ("Vertical");
     controller.SimpleMove(forward * curSpeed);
     
         if(Input.GetKey("w") || Input.GetKey("s"))
     {
         fuel -= fuelDeduct * Time.deltaTime;
     }
 
 if (fuel<0){
         Application.LoadLevel(0);
     }
     }
 @script RequireComponent(CharacterController)
 
 
 
 
 
 function OnGUI()
 {
 
         GUI.Label(Rect(250, 70, 100, 20), status1, style);
         GUI.Label(Rect(250, 100, 100, 20), fuel.ToString("f0") + percentage, style);
            GUI.Label(Rect(150, 100, 100, 20), "FUEL:", style);
            
            if (fuel<10){
     **********************
     }
 }  
 
 
 Ignore the majority of it, but where the **** are is where I believe the code should be, can anyone help me out a little? Thank you :) I've been at it for a while.
 
 Additional information: Script name : Movement.js
 
Comment
Add comment · Show 1
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 Muuskii · Sep 27, 2012 at 07:36 PM 0
Share

GUI text color

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Sep 27, 2012 at 08:45 PM

One way is to have two 'style' instead of one, set the other one to have the different color for normal text, then use it instead when the count reaches 10

Comment
Add comment · Show 2 · 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 Nercoe · Sep 27, 2012 at 10:30 PM 0
Share

Cheers for the reply Dave, I previously had this idea but now I know it's possible how would I go about implementing it?

} if (fuel<10){

I guess it would be something to do with the second style.

avatar image DaveA · Sep 28, 2012 at 10:18 PM 0
Share

Something like:

if (fuel < 10)

GUI.Label(Rect(150, 100, 100, 20), "FUEL:", style1);

else

GUI.Label(Rect(150, 100, 100, 20), "FUEL:", style2);

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

11 People are following this question.

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

Related Questions

Change color of Gui.Box background to solid black 1 Answer

JS changing gui box color 1 Answer

Color lerp once? 2 Answers

Shrink and change color of GUI 0 Answers

change Mesh.colors over time help? 2 Answers


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