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 Simon Foster · Jan 12, 2011 at 02:49 PM · materialchildalphagetcomponentinchildren

Changing alpha of a child Component in c sharp?

Hello,

I have an object called SwitchColorChanger which has a child plane component called PlaneLight. PlaneLight has a Particles/Alpha Blended Material which has a texture map on it. I want to either fade the rgb values up & down over time or fade the aplha value up & down over time to get a slowly pulsing glow effect. This will be pulsing for the lifetime of the object so most likely I need to hold some kind of reference for efficiency's sake. I'm having difficulty with this. I think I need to use GetComponentInChildren but I'm not sure how. Any help would be appreciated.

EDIT - for some reason clicking on comment isn't working at the moment so I'm posting my response to Jessy's reply here, with apologies for the unorthodox way it's been done:

'Thank you Jessy! That's much appreciated.

In reference to your query (for future people which come across this) The parent object is called SwitchColorChanger and has a script of the same name attached where this code goes. It has a child game object called PlaneLight which has a plane, a mesh renderer and a material called m_ColorChangerlight, which is a shader of type Particles/AlphaBlended. It was that material that I wanted to affect over time.

Now all I have to do is figure the most efficient way to increase & decrease the Alpha property over time and I'm sorted. And grateful. Thanks again Jessy.'

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

2 Replies

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

Answer by Jessy · Jan 12, 2011 at 03:47 PM

The most efficient reference you can cache is to the material itself. I don't know if you're saying that the Game Object is called PlaneLight, that a child has a script called PlaneLight attached, or both. I'm going to go with the previous assumption here, and you tell us if that's incorrect(*).

Material material;

void Awake () { material = transform.Find("PlaneLight").renderer.sharedMaterial; }

float Alpha { set { Color color = material.GetColor("_TintColor"); color.a = value; material.SetColor("_TintColor", color); } }

(*) Here's what you might do if PlaneLight is a class:

material = GetComponentInChildren<PlaneLight>().renderer.sharedMaterial;
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 jonc113 · Sep 03, 2012 at 12:44 AM

I found this answer by looking at the code of iTween, as it can control the alpha of children.

The trick is:

 foreach(Transform child in PARENTGAMEOBJECT)
    { DO_WHAT_YOU_WANT_WITH child.gameObject) ; }

This allows you to get the gameObject of all children - then you can deal with them the same way as any game object. My problem was in using `GetComponentsInChildren()` which returns components - and you can't change the color of components.

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

1 Person is following this question.

avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

change tint of image 0 Answers

Text not reverting back to original properties after gameplay 1 Answer

Noise on transparent material. 0 Answers

Way to get a material to alpha-fade along the texture? 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