Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 tora · Jan 23, 2010 at 05:56 PM · guitexture2dalphachange

Change Alpha on individual Texture2Ds

I want to change just the alpha of individual GUI textures.

I can do this in the OnGuI section like this

var alpha :float;

GUI.color = new Color(1,1,1,alpha);
    GUI.Label (Rect (100,10,128,128), aTexture2D);
    GUI.Label (Rect (200,10,128,128), bTexture2D);
    GUI.Label (Rect (300,10,128,128), cTexture2D);
...

But is there not a more modular way such as putting them in an array, and then cycling through changing the alpha of each Texture2D element in the array, without having to keep writing the coordinates etc. each time?

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
5
Best Answer

Answer by Brian-Kehrer · Jan 23, 2010 at 06:05 PM

No, but it's easy to make one. Just set this up in Start or Awake, then Call item.DrawMe()

public class MyTexture2D{ Rect gRect; Texture2D tex; Color col;

 public MyTexture2D(Rect theRect, Texture2D theTex, Color theColor){
     gRect = theRect;
     col = theColor;
     tex = theTex;
 }

 public void DrawMe(){
     Color tempCol = GUI.color;
     GUI.color = col;
     GUI.Label (gRect, tex);
     GUI.color = tempCol;
 }

 public Color color{
     get{
         return col; 
     }   
     set{
         col = value;    
     }
 }

}

and example usage:

public class MyGUI : MonoBehaviour {

 public Texture2D aTex;//actual texture
 MyTexture2D thing;
 public float alpha;

 void Start(){
     thing = new MyTexture2D(new Rect(100,10,128,128), 
                 aTex,
                 new Color(1,1,1,alpha));
 }
 void OnGUI(){
     thing.DrawMe();
 }

}

Comment
Add comment · Show 3 · 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 tora · Jan 25, 2010 at 03:16 PM 0
Share

Thanks $$anonymous$$ - that has answered 'several' questions.

avatar image liangfu · Apr 23, 2012 at 06:27 AM 0
Share

When I test it on my demo, the following error appears:

ArgumentException: You can only call GUI functions from inside OnGUI.

avatar image felixpk · Dec 04, 2013 at 01:43 PM 0
Share

void OnGUI(){

// put code here

}

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

2 People are following this question.

avatar image avatar image

Related Questions

change variable and Texture2D 1 Answer

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

Alpha not working in GUITex 0 Answers

Load level that was previously loaded! 1 Answer

Select part of the texture in GUI.DrawTexture 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