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 Zefaistos · Mar 30, 2012 at 07:04 PM · renderer.enabledgameobject.active

Show and hide object according to camera rotation.y position

I have a Main Camera rotating at 0,0,0 translate and I'm trying to make an object visible a few seconds after the camera gets it's visible field.

I have tried gameObject.active and renderer.enabled with no sucess.

 function Update() {
     
     if (Camera.main.transform.rotation.y <= 80 && Camera.main.transform.rotation.y >= 45) {
         renderer.enabled = true;
     }
     else {
         renderer.enabled = false;
     }
 }

 

 function Update() {
     
     if (Camera.main.transform.rotation.y <= 80 && Camera.main.transform.rotation.y >= 45) {
         gameObject.active = true;
     }
     else {
         gameObject.active = false;
     }
 }

None of them work. The object don't appears at camera.y 80 position. The code is attached only to the game object I want to show and hide. Thanks.

Comment
Add comment · Show 2
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 hijinxbassist · Apr 01, 2012 at 02:01 AM 0
Share

@Zefaistos Forgot to mention, you can use OnBecameVisible/OnBecameInvisible functions to deter$$anonymous$$e if the object is being viewed by any camera. You can then make a visible boolean true and false or just make the objects renderer true or false.

The OnBecameVisible function will always be true if the editors scene view camera is viewing the object. Just add these function to the script on the object/objects in question. Hope that helps.

avatar image Zefaistos · Apr 01, 2012 at 02:13 AM 0
Share

The problem is I don't want the object being visible all the time by the camera when it's looking at that point.

I'll explain exactly what I want:

The camera is rotating only on y axis, and sometime the camera will show some stars representing a constelation (scorpion constelation). After a few seconds that the camera shows the stars of the constelation, I want to display the object behind the stars, with a scorpion draw, fitting the art with the stars. And I want to hide again the scorpion art object (a cube with transparent texture) before the camera goes out of the stars of the constelation.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Zefaistos · Mar 31, 2012 at 06:02 PM

I'm new to Unity and don't know how to use Frustum Planes. What I want to do is not so relevant, so I decided to use StartCoroutine, hiding and showing the object every few seconds.

The camera.rotation.y on panel is that value, but it's indeed wrong. I have tested with a object attached to the camera, and the camera.y changes from > 0 and < 0, but never > 1.

Thanks for the answer. I'll try Frustum Planes later anyway.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

I am trying to create a togglable game menu using the ESC key 1 Answer

Unity 2019.4.9f1 - Toggle Show/Hide Gameobject with one keystroke. 1 Answer

Issue in gameObject.SetActiveRecursively 3 Answers

Access renderer from transform 1 Answer

Problem with Animator HEEEEEELP 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