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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by zeuo · May 11, 2012 at 03:25 AM · camerachildenableget

how to get the child of an instanteated object

i have a rocket that i create and there is a camera inside of it i want to be able to enable and disable that camera

         if (GUI.Button(Rect(450,280,80,80),"Rockets"))
     {
         
                     
             var bullit = Instantiate(rocketpref, GameObject.Find("rs").transform.position, Quaternion.identity);
         
         
         
         
     }
     if (GUI.Button(Rect(350,280,80,80),"cam"))
     {
         var newcam = bullit.Find("rocket/Camera").camera;    
         //var child = GameObject.Find("/Camera").camera;            
         if(newcam){ print("found");}
         //newcam.depth=1;
         
     }
 }
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
2
Best Answer

Answer by Berenger · May 11, 2012 at 03:36 AM

If the camera is a child of bullit, you can access that component that way :

 var cam : Camera = bullit.GetComponentInChildren.< Camera >();

(Edit : I usually program in C# but I try to write things in javascript here. But I mixed them both here, sorry about that !)

Comment
Add comment · Show 6 · 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 zeuo · May 11, 2012 at 03:48 AM 0
Share

can u put that in java please i dont know anything about c#

avatar image syclamoth · May 11, 2012 at 03:53 AM 2
Share

I'm pretty sure java won't help you here, it's not a language that Unity supports. In any case, the syntax in Java is virtually the same as in C#... In any case, you should learn C#. It's not actually any more complex than UnityScript (your programs will still need to work the same way), and it is a generally more useful language (because it's not a unique JavaScript variant that is only used in one place).

avatar image zeuo · May 11, 2012 at 03:56 AM 0
Share

i tryed the script but it dosnt work i want to disable the camera anyone know how

avatar image Lo0NuhtiK · May 11, 2012 at 03:56 AM 0
Share

Script Reference
If that doesn't help you convert this ONE line yourself, then I'd hire a programmer.

avatar image syclamoth · May 11, 2012 at 04:00 AM 0
Share

Or, do the smart thing, and buy all your program$$anonymous$$g assets from the Asset store. It's actually much cheaper than hiring someone to work for you constantly.

Show more comments
avatar image
1

Answer by syclamoth · May 11, 2012 at 03:59 AM

Code! To disable a camera that is the child of an object! In both UnityScript and C#!

 var childCam : Camera = bullit.GetComponentInChildren.<Camera>();
 if(childCam != null)
 {
     childCam.enabled = false;
 }

 Camera childCam = bullit.GetComponentInChildren<Camera>();
 if(childCam != null)
 {
     childCam.enabled = false;
 }

If you can't tell which is which, you need to do a little more homework.

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 zeuo · May 11, 2012 at 04:03 AM 0
Share

ty but i got Object reference not set to an instance of an object i have a camera inside of the rocket (which is being instan$$anonymous$$ted) called Camera so why isnt it working

avatar image syclamoth · May 11, 2012 at 02:18 PM 0
Share

What have you set 'bullit' to? I'm assu$$anonymous$$g that 'bullit' is the newly instantiated object.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

toggle being a child 1 Answer

rigidbody on parent has to effect the child players but not the child camera's attatched to the players 0 Answers

How to enable children of child game object? 1 Answer

parent object rotate with child camera 1 Answer

Disable multiple child components 1 Answer


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