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 /
avatar image
0
Question by FusionSausage · Oct 13, 2013 at 12:29 PM · instantiateobjecthide

Hide object when changing instantiation

I have a script which allows me to instantiate different objects with a "ghost object", which is the same object that's being instantiated, so I can rotate it real-time. Now, when I change between the objects the ghost object changes as well, which is good. Although now I have a problem. The ghost object is placing on the terrain when I instantiate, which seems logical. Is there any way I can "hide" the ghost object and when I click on a button I can show it again? What's the best way to do this?

Thanks

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

1 Reply

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

Answer by Tomer-Barkan · Oct 13, 2013 at 01:06 PM

What is a ghost object? Do you mean a prefab? Sharing your code might help.

If you want to instantiate an object and make it hidden from view, use this code:

 GameObject newObj = (GameObject)GameObject.Instantiate(prefab);
 newObj.renderer.enabled = false;

The second command will turn the renderer off, hence the new object will not be visible. Turn it back on if you want to make it visible again.

Comment
Add comment · Show 4 · 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 FusionSausage · Oct 13, 2013 at 03:25 PM 0
Share

The ghost object is the same prefab that gets placed down because I, as I said, need to rotate it in real-time. So that looks promising, but how can I only hide the object that follows the camera?

 if (chosenObject == 1) {
 
                 Object1.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
                     
                 
                 if (Input.GetButton("RotateInst")){
                     Debug.Log ("RotateInst cliked");
                     Object1.transform.Rotate(Time.deltaTime, 1, 0);
                     
                 }
 
             }
                 
                 if (chosenObject == 2) {
 
                 Object2.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
                 
                 if (Input.GetButton("RotateInst")){
                     Debug.Log ("RotateInst cliked");
                     Object2.transform.Rotate(Time.deltaTime, 1, 0);
                     
                 }
 
             }
                 
                 if (chosenObject == 3) {
 
                 Object3.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
                 
                 if (Input.GetButton("RotateInst")){
                     Debug.Log ("RotateInst cliked");
                     Object3.transform.Rotate(Time.deltaTime, 1, 0);
                     
                 }
 
             }
avatar image Tomer-Barkan · Oct 13, 2013 at 03:32 PM 0
Share

I don't know what "the object that follows the camera" is, but you simply set it's renderer to disabled:

 objectThatFollowsTheCamera.renderer.enabled = false;

Then when you instantiate a new object, you set it to true again:

 GameObject newObj = (GameObject)GameObject.Instantiate(gameObjThatFollowsTheCamera);
 newObj.renderer.enabled = true;
avatar image FusionSausage · Oct 13, 2013 at 04:03 PM 0
Share

You saved my life! Thank you! :D

avatar image Tomer-Barkan · Oct 13, 2013 at 04:05 PM 0
Share

Glad it helped. Good luck.

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

16 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

Related Questions

Random array issue C# 2 Answers

Destroy and instantiate far objects 2 Answers

How do you instantiate an object to be oriented along a vector3? 1 Answer

[Closed]Instantiate object to spesific location 1 Answer

How can i randomly create an array of objects without colliding one another? 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