playMaker

Author Topic: destroy when the object was off the screen  (Read 1660 times)

rik

  • Full Member
  • ***
  • Posts: 247
    • View Profile
destroy when the object was off the screen
« on: December 07, 2014, 06:59:49 AM »
Hi can some make simple script to know when the object was invisible

api refe http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnBecameInvisible.html

4ppleseed

  • Full Member
  • ***
  • Posts: 227
    • View Profile
Re: destroy when the object was off the screen
« Reply #1 on: December 12, 2014, 07:54:23 AM »
OnBecameInvisible is a strange one (unless it's recently been fixed), if you can still see the object in the scene view, it's still 'visable'. It's not to do with the camera or screen size.

Best way to kill things once they leave the screen is:
Get screen height and width, save as variables.
Get objects position and if it's greater/less than the screen height or width, kill.
Probably best not to check this every frame. Maybe set up a loop for a check every 1 second.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2484
  • Yup.
    • View Profile
    • Cleverous
Re: destroy when the object was off the screen
« Reply #2 on: December 12, 2014, 10:54:18 AM »
The Game Object Is Visible action should work.

Like 4appleseed said, watch out during tests because the scene view is also considered part of the cameras and contributes to whether something is considered visible or not.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: destroy when the object was off the screen
« Reply #3 on: April 14, 2016, 10:59:36 PM »
Hi,

 yep, but be very careful because in editor, the visibility also takes into account if the object is visible or not in the scene view, it's an easy miss.

Bye,

 Jean