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 Noah-1 · Jul 22, 2012 at 10:00 PM · guialphaslider

Use slider to modify alpha of a GUI Texture?

Hi guys, I have been working on some user interface stuff for my Mobile Game, now I want to let the user change the transparency of the GUI Controls using a slider like in the hierachy GUI Texture--> color-->sliders---> A, there is a slider to change the transparency of any GUI Texture, any ideas on how to do this but in the game view?

Check this image, I want to replicate the Alpha slider, and let the user control the transparency of the GUI Textures (Controls on the screen)alt text

Thanks

1.jpg (47.0 kB)
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
3
Best Answer

Answer by xSpectrum · Jul 23, 2012 at 01:37 AM

It's hard to answer if we don't know what GUI elements you're using. Are you using GUITextures (images)? Labels? Boxes? Buttons? As for the slider, are you asking how you would make the slider, or how you would make the preexisting slider affect alpha?

Script to make slider affect GUITexture alpha:

 var hSliderValue : float = 0.0;
 function OnGUI () 
 {
     hSliderValue = GUI.HorizontalSlider(Rect (25, 25, 100, 30), hSliderValue, 0.0, 100.0); //make the slider, and assign the value of it to a variable

  
 var colPreviousGUIColor : Color = GUI.color; //assign variable to current GUI color (just in case you're using a different value other than default)
 GUI.color = new Color(colPreviousGUIColor.r, colPreviousGUIColor.g, colPreviousGUIColor.b, hSliderValue/100); //Assign new color to GUI, only affecting the alpha channel
 GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height), yourTextureHere); //draw your texture(s)
 GUI.color = colPreviousGUIColor; //Reset alpha and color.
 DrawWithoutAlpha();
 }
 
 function DrawWithoutAlpha()
 {
     //put any GUI elements you don't want to be affected by alpha (or want a different alpha value) here
 }
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 xSpectrum · Jul 23, 2012 at 02:15 AM 0
Share

Why the -1?

avatar image AlucardJay · Jul 23, 2012 at 02:33 AM 0
Share

Yeah, why the -1 ? Bad form, leaving a thumb Down without even a comment. I am +1 thumb Up to this answer until someone can convince me otherwise =]

avatar image Noah-1 · Jul 23, 2012 at 04:32 PM 0
Share

Hi guys, thanks for the quick replies, I didn´t thumbed down, I actually think that is the way to do it, about my question, you´re right I missed some points there, I am using some GUI Textures, I know how to do the sliders but I am not really sure on how to make one that works like the alpha color on the GUI.

avatar image xSpectrum · Jul 23, 2012 at 05:28 PM 0
Share

Edited my answer. That should work, but please note I haven't tested it out myself. Just let me know if it doesn't work.

avatar image Noah-1 · Jul 23, 2012 at 09:05 PM 0
Share

Hey great script man, I just edited it a bit to fit my needs and it´s working! perfectly on my GUI controlls.

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

6 People are following this question.

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

Related Questions

Can I use a movie texture with alpha as a GUI object? 1 Answer

Crafting System - How to use a slider to show progress 0 Answers

How to make slider load variable on start 1 Answer

Alpha not working in GUITex 0 Answers

Non rectangular GUI Mask / Matte? 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