• 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 bisaniyehocam · Apr 12, 2011 at 07:08 PM · transformparentchildchildren

all parents of a transform

i want to chance the material color the parents of a transform. what is i need to use on for

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
0

Answer by Mike 3 · Apr 12, 2011 at 07:14 PM

this should do it (should be valid in js and c#)

var currentParent = transform.parent;
while(currentParent != null)
{
    var parentRenderer = currentParent.renderer;
    if (parentRenderer != null)
    {
        //do something with parentRenderer
    }
    currentParent = currentParent.parent;
}
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 bisaniyehocam · Apr 12, 2011 at 07:44 PM 0
Share

currentParent is not stable. i made with for(var parents:Transform.... but i cannot reach the children's parents. I need to make change color of all parents,childrens...

avatar image Mike 3 · Apr 12, 2011 at 08:18 PM 0
Share

What's the problem with it? That should change all parents when you call it (you shouldn't be storing currentParent anywhere)

avatar image bisaniyehocam · Apr 13, 2011 at 10:55 PM 0
Share

when i use your code , nothing happens , that cannot see the parents

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Make a simple tree 1 Answer

Why do we access children through an object's transform? 2 Answers

How to make multiple gameobjects child of one and the same transform (SCRIPT) 2 Answers

Get Children of Child and Deactivate/Activate on Demand 1 Answer

setting the parent of a transform which resdes in a prefab is dusabled to prevent data corruption 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges