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
2
Question by Marteen21 · Jun 27, 2014 at 02:46 PM · 2dspritedetectvisible

Detect if sprite is visible or not

I'm trying to figure out how to detect if a 2D sprite is visible from a specific camera, so there is a background sprite on which I am spawning (and growing) more sprites. I want to detect if the original background is still visible at any point or not. I was trying with

 private var cam : Camera;
 private var planes : Plane[];
 
 function Start() {
     cam = Camera.main;
     planes = GeometryUtility.CalculateFrustumPlanes(cam);
 }
 
 function Update() {
     if(GeometryUtility.TestPlanesAABB(planes,gameObject.collider2D.bounds))
         Debug.Log(gameObject.name + " has been detected!");
     else
         Debug.Log("Nothing has been detected");
 }

but unfortunately it doesn't detect if the sprite is covered with other sprites.

Thanks in advance.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Sisso · Jun 27, 2014 at 03:06 PM

Unity know when something is rendered, you simple need to find in the API how to access this information.

If the object is rendere to ANY camera is ok for you, simple use the Renderer.isVisible

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 Marteen21 · Jun 30, 2014 at 06:58 PM 0
Share

I tried you method but unfortunately it doesn't seem to work, I only use the main camera and built it on my phone(so the editors camera cant cause problems), the Renderer.isVisible stays true even if the sprite is covered with other sprites.

avatar image
0

Answer by unity_ZYfGXfm5YeGPkQ · Mar 18, 2019 at 07:22 PM

Hi ! I am facing the same issue.

I would like to detect if a sprite is visible to the player.

I tried OnBecameVisible /OnBecameInvisible / Renderer.isVisible but it also mark as visible the sprite that are idden under other layers.

If someone could help me, i would be very grateful. Thank you

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
0

Answer by sayginkarahan · Jan 20, 2021 at 10:03 PM

You can ray cast from the camera to your sprite position. And check the hit info.

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 Llama_w_2Ls · Jan 20, 2021 at 10:05 PM 0
Share

True. If the coordinates in screen space fit within the range of your display (e.g. 1920 x 1080), it's on your screen.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a Sprite visible 1 Answer

Detect animation end when drag all sprite to Hierarchy view 1 Answer

Create an invisible area behind 2D objects. 2 Answers

Sprite not visible from behind 0 Answers

How to alternate images in 2d unity 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