• 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 /
avatar image
0
Question by Pauls · Nov 25, 2012 at 10:04 PM · prefabfaderenderer.enabled

renderer and prefab: "enabled" does not work?

Hi,

would you know why t$$anonymous$$s code does not work? Here, "instance" instantiates the prefab, and i would like to $$anonymous$$de it, and show it only when i click on the right arrow. But instead it appears at the beginning, would you know how to ac$$anonymous$$eve t$$anonymous$$s?

I added a plane, a light and a character in an empty, and i added a "mesh renderer" to t$$anonymous$$s empty, then i put all of them in a prefab in the "Resources" folder :

Thanks


SOLUTION:

 var instance: GameObject;
 private var allRenderers : Component[];
 
 function Start () {
     instance = Instantiate(Resources.Load("totalR", GameObject));
     instance.renderer.enabled = false;
     
     allRenderers = instance.GetComponentsInC$$anonymous$$ldren(Renderer);
     for (var aRenderer : Renderer in allRenderers) {
            aRenderer.enabled = false;
     }
 }
 
 function Update () {
     
     if (Input.GetAxis("Horizontal")>0){
         instance.renderer.enabled = true;
         allRenderers = instance.GetComponentsInC$$anonymous$$ldren(Renderer);
         for (var aRenderer : Renderer in allRenderers) {
                aRenderer.enabled = true;
         }
     }
 }
Comment
Add comment · Show 6
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 whydoidoit · Nov 25, 2012 at 10:21 PM 1
Share

I'm guessing you have multiple renderers in that prefab, you'd need to turn them all off...

avatar image Pauls · Nov 25, 2012 at 10:57 PM 0
Share

@whydoidoit thanks! you were right, i edited my post ;) if i put all the code in the Update function, and want to know when the prefab has been loaded, can i just add a boolean right after the loop, and check when the boolean is "on" before checking the Input GetAxis ? Is there a better way?

avatar image whydoidoit · Nov 25, 2012 at 11:00 PM 1
Share

You don't need the instance.renderer.enabled = true as GetComponentsInChildren also returns the renderer on the actual object (confusingly!)

avatar image Pauls · Nov 25, 2012 at 11:35 PM 0
Share

@whydoidoit alright thanks, any idea about my second question? thanks anyway for your help

avatar image whydoidoit · Nov 25, 2012 at 11:39 PM 0
Share

So it's just appearing straight away still? Hmm. Perhaps a check for the actual key press? Using Input.GetKeyDown(...)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lacost · Nov 25, 2012 at 11:30 PM

Uniti has Active function for t$$anonymous$$s. SomeMonoBehaviour.Active(false) - will disable all scripts attached on game object (including render) and all of it's c$$anonymous$$elds. I gues t$$anonymous$$s is what you need.

PS. Active(bool val) - that's for unity 4. for 3. setActiveRecurseive(bool var) or smh like t$$anonymous$$s, don't remember)

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 whydoidoit · Nov 25, 2012 at 11:32 PM 0
Share

But that fully deactivates the object - it does not just make it invisible - the code in the Update function would not work using your suggestion.

avatar image lacost · Nov 25, 2012 at 11:37 PM 0
Share

as I understood from guastion, author do not need that's object att all until user click right arrow. But if some scripts on that gameobject sould work when it invisible GetComponentsInChildren - will be right design

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.

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

12 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

Related Questions

Can I get a prefab to render in front of GUI buttons created in script? 1 Answer

Script uses transform.position of Prefab instead of Instance 1 Answer

Getting Prefab Icon from AssetDatabase 0 Answers

Predefined Dynamic Navmesh? (With image) 0 Answers

Checking Position 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