Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SOLVED Destroy all game objects only visible on the screen

Discussion in '2D' started by captnhanky, Mar 18, 2019.

  1. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    Hi!

    I am trying to make a bomb that blows up all enemies that are visible on the player screen, but since the playfield is larger than the screen, the rest of the enemies must be not effected by the blast.

    How can this be done?

    Thanks
    Andy
     
  2. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    you could just get the corners of the camera in world space and check each object if it is within those, you wouldn't even need colliders
     
  3. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    Thanks..will dig deeper into that..great suggestion!
     
  4. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
  5. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    Thank you!!
     
  6. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    I experienced some problems when having two cameras (one for radar) with this method :
    Turning off the radar camera and then using isVisible immediately after that for the main camera does not work.

    I solved this problem by using a coroutine that waits for at least one frame after shutting off the radar camera before using isVisible on the main camera.
    This works as expected.
     
    Last edited: Mar 18, 2019
    beanie4now likes this.