• 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 Max_Res · Feb 01, 2015 at 05:56 PM · renderer.enabled

How to make a gameObject invisible in unity

I am attempting to make a Unity gameObject invisible through code. So far I have tried (On a script attached to the gameObject I want to make invisible): t$$anonymous$$s.renderer.enabled = false t$$anonymous$$s.enabled = false t$$anonymous$$s.gameObject.enabled = false t$$anonymous$$s.gameObject.renderer.enabled = false And on my player script: other.gameObject.enabled = false other.gameObject.renderer.enabled = false I have also tried Destroy (other.gameObject) but it doesn't ac$$anonymous$$eve what I want from it.

Thanks for your help

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
0

Answer by AngryBurritoCoder · Feb 01, 2015 at 09:48 PM

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
1

Answer by Mr. Mud · Feb 01, 2015 at 10:02 PM

It seems like you tried a lot of ways to turn the object invisible. But where exactly did you place these statements? Some functions get called automatically by Unity, w$$anonymous$$le others won't. Also, when you state that it does not ac$$anonymous$$eve the effect you want, do you mean that the object does not become invisible? Or is it the way it becomes invisible (in an instant) that you don't like? The latter requires some more work.

Here is an example of an script that will disable a GameObject in its entirety; it won't be rendered, physics won't affect it and Updated functions on its components won't be executed. Do note however that t$$anonymous$$s might or might not work depending on the version of Unity you are running.


 using UnityEngine;
 
 public class Example : MonoBehaviour
 {
     public void Awake()
     {
         t$$anonymous$$s.gameObject.SetActive(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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Show and hide object according to camera rotation.y position 1 Answer

2D project - player respawn delay problem 0 Answers

How do I make different gameobjects appear, every time you click the GUI.button? 2 Answers

How to whrite in c# the code: onMouseEnter Hide mesh 1 Answer

renderer and prefab: "enabled" does not work? 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