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
1
Question by deeds0l · Apr 01, 2014 at 02:14 PM · coloralpha

Changing the alpha of Mesh Renderer

Hi, I am trying to make a certain item blink when time is almost expired. I want to change the alpha to 0 but the opacity does not change at all.

I did it this way:

 itemWeapon.GetComponentInChildren<MeshRenderer>().material.color = new Color(1f,1f,1f,0f);

I tried to print the color out and it says RGBA(1.000, 1.000, 1.000, 0.000) but the object is still very visible.

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

Answer by Eric5h5 · Apr 01, 2014 at 02:34 PM

You need to use a shader that supports transparency, but it would be better to simply disable the renderer instead.

Comment
Add comment · Show 4 · 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 deeds0l · Apr 01, 2014 at 04:51 PM 0
Share

how do I know if my shader supports transparency. I just used the default mesh renderer after I imported it from blender.

avatar image deeds0l · Apr 01, 2014 at 05:06 PM 0
Share

I tried disabling the renderer but only one child of my object is disabled. How do I disable the rest of the children in my mesh renderer?

I used

itemWeapon.GetComponentInChildren().renderer.enabled = false;

do I need to loop it to get all the children?

avatar image deeds0l · Apr 01, 2014 at 06:27 PM 0
Share

fixed it by doing this

 for(int i=0; i< itemWeapon.GetComponentsInChildren<$$anonymous$$eshRenderer>().Length; i++){
                         itemWeapon.GetComponentsInChildren<$$anonymous$$eshRenderer>()[i].renderer.enabled = false;
                     }

is there a more optimized solution to this?

avatar image smash228 deeds0l · Apr 03, 2018 at 04:47 PM 0
Share

A more optimized version would be:

 List meshRenderers = itemWeapon.GetComponentsInChildren<$$anonymous$$eshRenderer>();
 
  for(int i=0; i< meshRenderers .Length; i++){
                          meshRenderers[i].renderer.enabled = false;
                      }

avatar image
2

Answer by smashingy0u · Apr 01, 2014 at 02:49 PM

Your code is perfectly fine. The shader on your object doesn't support alpha. i tried transparant/ Bumped diffuse and that one seemed to work. you can try other shaders for yourself ;)

edit: to add to my comment i'd assume that you already have a material added to your gameobject?

Comment
Add comment · Show 2 · 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 deeds0l · Apr 01, 2014 at 04:49 PM 0
Share

I do have a material added. In fact I have 6 materials on my gameobject. How can I use other shaders? Do you mean add a shader component to my gameobject?

avatar image smashingy0u · Apr 02, 2014 at 08:31 AM 0
Share

No, the shader is an attribute in the material tab in the inspector. its a drop down box

avatar image
1

Answer by djfunkey · Apr 01, 2014 at 02:31 PM

colour.a = 0;

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
0

Answer by Shadoninja · Jul 07, 2018 at 01:33 AM

To make @smashingy0u's answer a little clearer, as long as there is a material on your Mesh Renderer, you can just do something like this to make a text mesh invisible:


 TextMeshGamObject.GetComponent<MeshRenderer>().material.color = new Color(1f, 1f, 1f, 0f);
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

26 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

Related Questions

How to make a "Click to Continue" text message? 1 Answer

Strange artifacts on Vertex Color Shader 0 Answers

Change Alpha of Text via Code? 1 Answer

Trying to make sprite's alpha decrease to 0 in order to make it dip to black but it seems to be randomly glitching out 1 Answer

Can't animate Material.Color properties 3 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