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 dendens2 · Apr 03, 2013 at 06:22 PM · javascriptguiongui

GUI opacity.

Two questions.

1) Does OnGUI() update every frame like Update();?

2) Is there a way I can remove a GUI element or even better set the opacity(I could not find anything in the scripting reference)

THANK YOU!

Comment
Add comment
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

1 Reply

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

Answer by whydoidoit · Apr 03, 2013 at 06:25 PM

OnGUI updates multiple times per frame (one of the reasons it is slow and soon to be replaced). OnGUI gets called for layout, repaint and for each mouse messages, key press etc.

To remove an element, just don't include it! In other words put an if(something) {} around it.

You can set the GUI.color property to a transparent flavour of white before drawing the item and reset it afterwards to make it appear transparent/semi transparent (plus of course you could colour it something else entirely).

   GUI.color = new Color(1,1,1,0.5f);
   if(shouldDraw)
   {
       if(GUILayout.Button("I'm not all there"))
       {
       }
   }
Comment
Add comment · Show 5 · 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 dendens2 · Apr 03, 2013 at 06:32 PM 0
Share

The problem is, what happens if it is an imported texture? Can you still change the color? Is it possible to make a circle with code? Also the if statement does not seem to work. Thanks

 var crosshairTexture: Texture2D;
 var crosshairPosition: Rect;
 var crosshairActive = true;
 var playerWalkScript: Player$$anonymous$$ovementScript;
 var gunScript: GunScript;
 var crosshairSize: float = 5;
 
 function Start()
 {
 
     playerWalkScript = GameObject.FindWithTag("Player").GetComponent(Player$$anonymous$$ovementScript);    
 
 }
 
 function Update()
 {
     if (Input.GetButtonDown("Fire2"))
     {
     
         crosshairActive = false;
     
     }
     else
     {
     
         crosshairActive = true;
     
     }
     
     gunScript = playerWalkScript.currentGun.GetComponent(GunScript);
     crosshairPosition = Rect(((Screen.width )  / 2) -  (crosshairPosition.width / 2), ((Screen.height ) / 2) -  (crosshairPosition.height / 2), crosshairTexture.width * gunScript.currentAccuracy * crosshairSize, crosshairTexture.height * gunScript.currentAccuracy * crosshairSize); 
 
 }
 
 function OnGUI()
 {
 
     if(crosshairActive == true)
     {
     
         GUI.DrawTexture(crosshairPosition, crosshairTexture);
     
     }
     
     if (gunScript.ammoClip == 0)
     {
     
         GUI.backgroundColor = Color.red;
         
     }
     
 
 }
avatar image dendens2 · Apr 03, 2013 at 06:35 PM 0
Share

Oh, wow, I forgot to change it from GetButtonDown to GetButton. Never $$anonymous$$d the if statement. Is it still possible to change the color of an imported img?

avatar image whydoidoit · Apr 03, 2013 at 06:42 PM 0
Share

I'm pretty sure images draw with GUI.color (or perhaps GUI.backgroundColor), but I'm normally drawing icons.

avatar image dendens2 · Apr 03, 2013 at 06:53 PM 0
Share

No, both

GUI.backgroundColor = Color.red; and GUI.color = Color.red;

did not work. Anyways the most important thing was the removal of the object, Thanks!

avatar image whydoidoit · Apr 04, 2013 at 01:57 AM 0
Share

Oh actually - I know why I was thinking that - you can display the texture in a GUILayout.BeginArea and then actually display it like this:

   GUILayout.Label(theTexture);

I think that's how I've done it previously.

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

Setting Scroll View Width GUILayout 1 Answer

BCE0044: expecting (, found 'OnGUI'. 1 Answer

GUI Crosshair 2 Answers

turn off items from GUI 0 Answers

GUI Not updating 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