Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
16
Question by Busil · Jan 04, 2016 at 07:21 PM · colorimagealpha

How to modify color.alpha in UI Image?

Hi, is it possible to modify alpha in image? I tried to write some code but it doesn't work.

 public Image image;
 
         void Start () {
     
             image = GetComponent<Image>;
     
             image.color.a = 1f;
         }



Thanks for your help and ideas :)

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

4 Replies

· Add your reply
  • Sort: 
avatar image
42

Answer by Denvery · Jan 04, 2016 at 07:38 PM

It is impossible to edit r,g,b or a separately by color.a = 1f. You can assing only whole Vector3 to color property. So, please use the next code:

    public Image image;
    void Start () 
    {
          image = GetComponent<Image>();
          var tempColor = image.color;
          tempColor.a = 1f;
          image.color = tempColor;
    }
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 Busil · Jan 04, 2016 at 08:40 PM 0
Share

Could you write the same code in C#? var is something that is used in JS as I remember.

avatar image Denvery Busil · Jan 04, 2016 at 08:40 PM 2
Share

This is C# :)

avatar image Busil Denvery · Jan 04, 2016 at 08:43 PM 1
Share

Well, I'm silly I guess :) Then.. could you tell me what "var" means?

Show more comments
avatar image Busil · Jan 04, 2016 at 08:45 PM 0
Share

And there is an error in your code: "Cannot convert method group GetComponent' to non-delegate type UnityEngine.UI.Image'. Consider using parentheses to invoke the method "

avatar image Denvery Busil · Jan 04, 2016 at 09:24 PM 1
Share

You have missed brackets in GetComponent<Image> Right:

 GetComponent<Image>()

avatar image
15

Answer by WanderRook · May 31, 2018 at 11:54 AM

It is also possible to create a new Color using the original image color's red, green and blue values and the desired alpha value and assign the new Color to the image color:

 public Image image;
   void Start () 
   {
         image = GetComponent<Image>();
         image.color = new Color(image.color.r, image.color.g, image.color.b, 1f);
   }

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

Answer by unity_WXIWcvH1Gzms2A · Dec 22, 2018 at 06:26 AM

You can using extension method for this:

 public static T ChangeAlpha<T>(this T g, float newAlpha)
         where T : Graphic
     {
         var color = g.color;
         color.a = newAlpha;
         g.color = color;
         return g;
     }

And using: Image.ChangeAlpha(0.5f);

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

Answer by grizzly101 · Jan 02, 2020 at 12:43 PM

So not sure if this was addressed by folks but keep in mind that alpha must be set in code using a value between 0 and 1. I was trying to set it to a value between 0 and 255 because that appears to be how the color wheel in the inspector did it. Of course the Unity manual shows this to be the case, but I didn't look there first.

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

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

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

Related Questions

Black Image with custom material in "Game" when color is displayed in "Scene" 0 Answers

Changing a material.color.a 1 Answer

Sprite color is stuck after changing it in script 0 Answers

Change color of a Filled image from script 0 Answers

How to find the most present color in an image ? 0 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