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 Creat0r · Oct 22, 2013 at 09:47 PM · colorguitexturealpha

Problem with GUITexture.color.a

Hi. Look at this snippet:

 GameObject.Find("GUI Texture Pause").guiTexture.color = Color.black;
 GameObject.Find("GUI Texture Pause").guiTexture.color.a = 0.4f;

First line of code works but second doesn't. I get this message:

Assets/Standard Assets/Scripts/Pause.cs(11,65): error CS1612: Cannot modify a value type return value of `UnityEngine.GUITexture.color'. Consider storing the value in a temporary variable

Help me who can please!

Comment
Add comment · Show 2
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 RyanZimmerman87 · Oct 22, 2013 at 09:39 PM 0
Share

Judging from your error message it sounds like you need to create a Game Object for the texture.

Example:

 public GameObject GUITexturePause;
 
 void Start()
 {
 GUITexturePause = GameObject.Find("GUI Texture Pause");
 }
 

I'm wondering why you would want to change the color at run time it might be best to just have 2 textures if you only have 2 colors, but either way should work fine assu$$anonymous$$g your code works once you set up the game object variable like my example.

I've never personally tried to change colors of textures like that so I'm not 100% sure, I only change colors for fonts.

avatar image meat5000 ♦ · Oct 22, 2013 at 10:09 PM 0
Share

Perhaps change the colour or the Texture2D associated with the GUITexture ins$$anonymous$$d.

2 Replies

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

Answer by robertbu · Oct 22, 2013 at 10:11 PM

The error message means you need to put it in a temporary variable and then put it back:

 Color colorT = guiTexture.color;
 colorT.a = 0.4f;
 guiTexture.color = colorT;
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 Creat0r · Oct 22, 2013 at 10:45 PM 0
Share

Oh, Thank you, guys! Especially robertbu. Your idea really work. And, well, it works when picture is colored! But, if GUITexture has color.a property, why it's imposible to change it directly?

avatar image rutter Creat0r · Oct 22, 2013 at 10:50 PM 1
Share

It's because the color is passed by value. Sort of like passing an int to a function: changes made inside the function don't normally alter the value of the variable that was passed in.

guiTexture.color gives you a copy of the color; editing the copy won't directly edit the original. You can ins$$anonymous$$d edit the copy and send it back, which is what you're doing with that temp variable.

avatar image Creat0r · Oct 22, 2013 at 11:27 PM 0
Share

Thanks for explanation!

avatar image
0

Answer by YoungDeveloper · Oct 22, 2013 at 10:35 PM

If you have problems with changing alpha on run-time, check out this topic i gave answer long time ago, should help.

http://answers.unity3d.com/questions/516744/change-texture-alpha-value-on-runtime.html

Comment
Add comment · Show 1 · 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 Creat0r · Oct 22, 2013 at 10:50 PM 0
Share

Thanks. !!

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

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

guiTexture color half alpha White? 1 Answer

Modifying and Saving a GUITexture 0 Answers

How to Make a Character Flicker? 1 Answer

Change background color of a GUI.BOX C# 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