Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Destroying one way platform

Discussion in '2D' started by contact_unity206, Feb 13, 2023.

  1. contact_unity206

    contact_unity206

    Joined:
    Jan 15, 2019
    Posts:
    2
    Hi,

    Using the one way platform effector is very simple and straightforward, that's great, however I can't figure how to use colliders to detroy the platform when it is outside the screen.

    My favorite idea was to use a edgeCollider2D trigger attached to the camera's lower bound, so any platform passing through would be destroyed from OnTriggerEnter2D. The problem is this callback is not called because of the platforms' effector.

    Instead I could check the platform position and detect wether it is out of screen, but I prefer not to do so for performance concerns.
     
  2. Bean_Office

    Bean_Office

    Joined:
    Jun 18, 2018
    Posts:
    14
    I'm pretty sure an event fires when an object goes off screen.
    Code (CSharp):
    1.  void OnBecameInvisible() {
    2.          Destroy(gameObject);
    3.      }
     
  3. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,343
    Are you even experiencing performance issues if you don't apply this potential fix?