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 Cerbion · May 30, 2012 at 06:47 AM · guitexturescreenopacityblood

GUI: make texture visible/invisible?

Hey guys, I am still working on the FPS. And I am currently implementing a Bloodscreen (like in Call of Duty), so what I basically want, is that the Player will see Bloodscreen 1 (a .png texture) if his health is lower than 90, the second one if the player health is under 60 and the last one if the player health is less than 30 percent... But I am not sure how to make it, I thought of setting the "a" color which is obviously the opacity to 0 and back to 255 if the case switches, however I don't know how to do it exactly, and appreciate every helpful post from you! :) oh and btw, here's the code which I already implemented, to show it "always":

 GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), Blood1, ScaleMode.StretchToFill, true);

(and this is working for all resolutions, perfectly, but still, it's always there.. kinda annoying :/

sincerely,

Cerbi

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 GuyTidhar · May 30, 2012 at 06:48 AM

Here is an option with changing the alpha:

 public var bloodTexture : Texture2D;
 
 var currentHealth : int;
 var MaxHealth : int;
 private var currentAlpha : float = 1;
 
 function Start()
 {
     // This works only if you set the health before enabling this script
     // You can remove this line and set the MaxHealth on the inspector
     MaxHealth = currentHealth;
 }
 
 function Update()
 {
     // Change the alpha values the way you like it
     if ( currentHealth >= 0.9*MaxHealth )
         currentAlpha = 0;
     else if ( currentHealth >= 0.6*MaxHealth )
         currentAlpha = 0.25;
     else if ( currentHealth >= 0.3*MaxHealth )
         currentAlpha = 0.5;
     else
         currentAlpha = 0.75;        
 }
 
 function OnGUI()
 {
     var color = GUI.color;
 
     GUI.color.a = currentAlpha;
     GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), bloodTexture, ScaleMode.StretchToFill, true);

     GUI.color = color;

     // Now call more stuff
 }
Comment
Add comment · Show 6 · 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 GuyTidhar · May 30, 2012 at 07:49 AM 0
Share

Not a problem:

Just look at the edited OnGUI()

You save the current color and use it once you have set the blood texture

avatar image GuyTidhar · May 30, 2012 at 07:51 AM 0
Share

Also, if you wish to use the same texture, there is no need for duplicating the reference to the texture.

avatar image Fattie · May 30, 2012 at 08:23 AM 0
Share

To add a comment ... very simply click "edit" on your original question. Or, click "comment" below the other guy's answer.

avatar image Cerbion · May 30, 2012 at 08:28 AM 0
Share

Thanks! Works perfectly :)

avatar image Cerbion · May 30, 2012 at 08:30 AM 0
Share

@Fattie: Sorry, I missclicked, but I changed it ;)

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I take maximum screenspace for Gui 1 Answer

Keeping a GUI texture from moving during change of screen size 2 Answers

GUI.DrawTexture Center on screen 1 Answer

GUITexture scaling with aspect ratio? 1 Answer

How do you auto scale the space between Gui Buttons? 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