Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 UnbreakableOne · Aug 18, 2015 at 11:26 AM · camerarenderervisibilityvisible

Problem is "renderer.isVisible"

Hi,

To determine when my objects are out of screen for screen wrapping I use "renderer.isVisible" but it returns true if the object is visible in the editor panel and out of screen in game panel and it makes it cumbersome to test the game in the editor.

Is there anyway to overcome this? Perhaps by using a better approach to determine if an object is out of screen in a 2D game with orthographic camera.

Thanks.

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 Ekta-Mehta-D · Aug 19, 2015 at 05:41 AM 0
Share

hey do u get any solution ?

3 Replies

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

Answer by UnbreakableOne · Aug 19, 2015 at 12:42 PM

Solution I came up with was to calculate bounds of the screen in world space and check if a game object is inside those.

In Awake() or something:

         screenBottomLeft = cam.ViewportToWorldPoint(new Vector3(0, 0, transform.position.z));
         screenTopRight = cam.ViewportToWorldPoint(new Vector3(1, 1, transform.position.z));
 
         screenBottomRight = cam.ViewportToWorldPoint(new Vector3(1, 0, transform.position.z));
         screenTopLeft = cam.ViewportToWorldPoint(new Vector3(0, 1, transform.position.z));
 

and then:

     bool amIVisible()
     {
         if (transform.position.x > screenTopRight.x || transform.position.x < screenTopLeft.x)
         {
             return false;
         }
         if (transform.position.y > screenTopRight.y || transform.position.y < screenBottomRight.y)
         {
             return false;
         }
 
         return 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 Ekta-Mehta-D · Aug 18, 2015 at 12:07 PM

Hii..

Look at this :

Check Object is out of the camera view

Use this function and Attach this script to object and make operation you want.

 void OnBecameInvisible() {
         //do something here
     }

This may work for you . Thanks.

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 UnbreakableOne · Aug 18, 2015 at 12:29 PM 0
Share

OnBecameInvisible has the same problem.

avatar image
1

Answer by brunopava · Aug 18, 2015 at 12:13 PM

I have a script that can be aplied to this.

     private float _clampingAngle = 90f;
     public bool isVisible = false;
     private Camera _mainCamera;
     private Transform _itSelf;
     private Transform _cameraTransform;
 
     private void Awake()
     {
         _mainCamera = Camera.main;
         _cameraTransform = _mainCamera.transform;
         _itSelf = transform;
     }
 
     private void Update()
     {
         if (Vector3.Angle (_itSelf.position - _cameraTransform.position, _cameraTransform.forward) > _clampingAngle)
             return;
         Vector2 screenPosition = _mainCamera.WorldToViewportPoint(_itSelf.position);
         if(screenPosition.x >= 0 && screenPosition.x <=1 && screenPosition.y >=0 && screenPosition.y <=1)
         {
             isVisible = true;
         }
         else
         {
             isVisible = 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.

Follow this Question

Answers Answers and Comments

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems with the visibility of an animated object 1 Answer

How not to render a specific object ? 1 Answer

Renderer.isVisible always returning false 2 Answers

How to know when a object is in the viewport? 1 Answer

GameObject invisible at certain camera angles 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