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 question was closed Oct 21, 2014 at 05:18 PM by bobin115 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by bobin115 · Oct 21, 2014 at 04:35 PM · starthide

hide object start script

what i want to do is hide the child at the start, then when "B" is pressed the object appears. however i don't know how to make it hide at the start. my awful attempt is below:

  function Start (child.renderer.enabled = false;) 
  function OnTriggerStay(trigger : Collider) {
        if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.B)) {
            var child = transform.GetChild(0);
            child.renderer.enabled = true;
       }
   }

i know this doesnt work, can someone show me how to write this properly

thanks

Comment
Add comment · Show 5
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 Diablo404 · Oct 21, 2014 at 04:40 PM 0
Share

Have you multiple objects to disable at the beginning? or juste a specific one?

avatar image bobin115 · Oct 21, 2014 at 04:41 PM 0
Share

just the one "child"

avatar image CarnivorousHam · Oct 21, 2014 at 04:49 PM 0
Share

So you want it to reappear when the user presses the B key? If so, why are you using an OnTriggerStay Function? That kind of thing would be better served in an Update function.

avatar image bobin115 · Oct 21, 2014 at 04:50 PM 0
Share

yes,the second part works fine i have tested it, i just need to know how to make the child hide at the start

avatar image CarnivorousHam · Oct 21, 2014 at 04:55 PM 0
Share

You'll either have to declare and initialize the child variable earlier in your script (I.$$anonymous$$ before the Start function) OR set the child's renderer to disabled in the scene view (Look for it in the inspector, should be a little checkbox).

4 Replies

  • Sort: 
avatar image
1

Answer by EvilTak · Oct 21, 2014 at 04:53 PM

Best approach would be this:

 void Start(){
     child.renderer.enabled = false;
 }
 
 void Update(){
     if(Input.GetKeyDown("b"))
         child.renderer.enabled = true;
 }
Comment
Add comment · Show 1 · 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 bobin115 · Oct 21, 2014 at 04:58 PM 0
Share

thanks for the help. i did not use your answer. i used

  function Start(){
  var child = transform.GetChild(0);
      child.renderer.enabled = false;
  }

  

cheers

avatar image
1

Answer by g8minhquan · Oct 21, 2014 at 04:54 PM

 function Start ( ) 
 {
    var child = transform.GetChild(0);
    child.renderer.enabled = false; 
 }
Comment
Add comment · Show 1 · 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 bobin115 · Oct 21, 2014 at 04:59 PM 0
Share

thanks, i always forget to declare "child"

avatar image
0

Answer by Diablo404 · Oct 21, 2014 at 06:49 PM

Well, you didn't really answered my question. But, let's assume you have just one. You could use: GameObject.Find("NameOfYourObject").renderer.enabled = false; It's dirty but should work.

Regarding your code you could also do:
GameObject.FindWithTag("Player").transform.GetChild(0).renderer.enabled = false. Once again, this one is dirty and would not work if you have multiple gameobjects with the "Player" tag.

Finally, the best way is to declare a variable as GameObject. Fill it in the inspector and then call it in start like so: var myChild : GameObject; function Start { myChild.renderer.enabled = false; }

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 unitygamer · Oct 21, 2014 at 06:59 PM

  • do you have scripts attached to the 'child' that you would use ? or else you could just assign the child to a variable via inspector and use

    var myChild:GameObject; function Start () { myChild.gameObject.SetActive (false); }

note:this disables the entire child including the scripts on it.

  • or you could try carivorousHam's answer by setting the renderer checkbox to false(untick) in the inspector when outside playmode and enable the renderer as in your above script

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

Follow this Question

Answers Answers and Comments

33 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

hide child object script - help 1 Answer

button question 1 Answer

Need Help with rebuildable barricade system like in Call Of Duty Zombies 1 Answer

Help Solve This 2 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