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 /
  • Help Room /
avatar image
2
Question by wensk · Aug 09, 2012 at 03:31 PM · hide

how to hide and unhide object

Hi,all. I have a object named obj1 in the scene, now I wish press a button to hide it, then press again to unhide it, I have writed some code bellow, but the code can hide obj1 only, cannot unhide it.Any help plz? thank you very much!

 #pragma strict
 
 function OnGUI()
 {
    if(GUI.Button(Rect(0,0,200,100),"Click Me"))
    {
    var obj1=GameObject.Find("obj1");
    if (!obj1){
    obj1.SetActiveRecursively(true);}
    else
    {obj1.SetActiveRecursively(!obj1.active);
    }
    }
 }
 
 function Start () {
 
 }
 
 function Update () {
 
 }
Comment
Add comment · Show 1
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 CManzione · May 03, 2016 at 04:39 AM 0
Share

Can you hide a skybox but still let it light the scene?

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by flare38888 · Feb 21, 2021 at 06:08 PM

@wensk

//This will work.

gameObject.SetActive(False/true);

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 DannyB · Aug 09, 2012 at 04:18 PM

See if renderer.enabled on the game object suits your needs.

EDIT:

renderer.enabled is definitely capable of showing and hiding. Your problem lies elsewhere - your IF statement should check for if( obj1.renderer.enabled ).

Also, you can easily toggle on or off, try the below code (not tested, but you should get the idea).

  var cubeRenderer:Renderer;
  var obj1:GameObject;
 
  function Start() {
      obj1=GameObject.Find("obj1"); 
  }
 
  function OnGUI() { 
      if( GUI.Button(Rect(0,0,200,100),"my button")) { 
          obj1.renderer.enabled = !obj1.renderer.enabled;
      }
  }

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 wensk · Aug 10, 2012 at 11:54 AM

Thank you,Danny.I watched this page and used renderer.enabled script,but it still only hide object,not unhide.

 #pragma strict
 var cubeRenderer:Renderer;
 function OnGUI()
 {
  if(GUI.Button(Rect(0,0,200,100),"my button"))
  {
   var obj1=GameObject.Find("obj1");
    if(!obj1){
       obj1.renderer.enabled = true;}
    else{
       obj1.renderer.enabled = false;
  }
  }
 }
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 DannyB · Aug 10, 2012 at 12:10 PM 0
Share

You should use the comments for such posts, not a new answer. Also when posting a question or answer, you should format your code, as it will be easier for people to help you.

I updated the answer above.

avatar image wensk · Sep 29, 2012 at 09:36 AM 0
Share

Hi, Danny,I have 2 tyres attached to the car, after enter the game, tyreA is hide,tyreB is display.I wish press a button to display tyreA and hide tyreB, press again to hide tyreA and display tyreB, how to do that ? Thanks.

var tyreA : GameObject; var tyreB : GameObject;

if(GUI.Button(Rect(220,340,200,80),"tyre"))

if(tyreA!=null) { { tyreA.renderer.enabled = true; tyreB.renderer.enabled = false; } else { tyreA.renderer.enabled = false; tyreB.renderer.enabled = true; } }

function Start () { tyreA=GameObject.Find("tyreA"); }

function Update () {

}

avatar image
0

Answer by flare38888 · Feb 22, 2021 at 01:49 PM

//Use this to hide/unhide.

gameObject.IsActive(false/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 flare38888 · Feb 21, 2021 at 06:01 PM 0
Share

You can do this or you can do a more complicated thing where to hide it first you find the transform, then delete it and then to get it back create a new one with the same transform.

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

10 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

Related Questions

Receiving a missing reference exception error but everything is still there. 0 Answers

global variables in shader graph?? 2 Answers

Main Menu -> Slider (for music volume) and Back button 0 Answers

Object didnt hide while animation playing 0 Answers

How can I make the character jump between the boxes? 0 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