• 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 $$anonymous$$de the c$$anonymous$$ld at the start, then when "B" is pressed the object appears. however i don't know how to make it $$anonymous$$de at the start. my awful attempt is below:

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

i know t$$anonymous$$s doesnt work, can someone show me how to write t$$anonymous$$s 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
avatar image bobin115 · Oct 21, 2014 at 04:41 PM 0
Share
avatar image CarnivorousHam · Oct 21, 2014 at 04:49 PM 0
Share
avatar image bobin115 · Oct 21, 2014 at 04:50 PM 0
Share
avatar image CarnivorousHam · Oct 21, 2014 at 04:55 PM 0
Share

4 Replies

  • Sort: 
avatar image
1

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

Best approach would be t$$anonymous$$s:

 void Start(){
     c$$anonymous$$ld.renderer.enabled = false;
 }
 
 void Update(){
     if(Input.GetKeyDown("b"))
         c$$anonymous$$ld.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
avatar image
1

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

 function Start ( ) 
 {
    var c$$anonymous$$ld = transform.GetC$$anonymous$$ld(0);
    c$$anonymous$$ld.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
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.GetC$$anonymous$$ld(0).renderer.enabled = false. Once again, t$$anonymous$$s 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 myC$$anonymous$$ld : GameObject; function Start { myC$$anonymous$$ld.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 'c$$anonymous$$ld' that you would use ? or else you could just assign the c$$anonymous$$ld to a variable via inspector and use

    var myC$$anonymous$$ld:GameObject; function Start () { myC$$anonymous$$ld.gameObject.SetActive (false); }

note:t$$anonymous$$s disables the entire c$$anonymous$$ld 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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our 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