Jump to content
  • Advertisement
Sign in to follow this  

Unity Unity c# scripting acsessing components and understanding the hierarchy

This topic is 2072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:








   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.




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

Edited by Psilobe

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!