Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Unity c# scripting acsessing components and understanding the hierarchy


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Psilobe   Members   -  Reputation: 193

Like
0Likes
Like

Posted 19 February 2013 - 09:16 AM

I'm using unity combined with c# but I'm having trouble with navigating the hierarchy from within my scripts to get access to specific components.

 

For example my hierarchy looks like this:

 

 

Ship

   Box01

   Box02

     Cylinder02

   Cylinder01

   Main Camera

 

 

Box02 got a component in which needs access to the camera component in the Main Camera. 

 

I've figured that what I need to do should be to somehow navigate to the Main Camera gameObject and then use the getComponent function but I'm not sure how to do it. I tried getting to the Ship gameObject by using transform.parent but that didn't seem to work.

 

I've been trying to find a good resource which explains this but I cant find one.

 

 

I finally found something that helped me.

 

http://answers.unity3d.com/questions/125847/trouble-accessing-child.html

 

The first answer here helped my immensely so if anyone else runs in to similar trouble then go here.


Edited by Psilobe, 19 February 2013 - 11:17 AM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS