Search Unity

Removed gameobjects from time to time

Discussion in '2D' started by SamVorst, Dec 3, 2019.

  1. SamVorst

    SamVorst

    Joined:
    Nov 28, 2019
    Posts:
    63
    Hi,

    I have a level with many gameobjects, but I would to have not all gameobjects in the scene because prestations. But that they spawn on a moment that my player comes near to it. How do i do this?

    Thanks, Sam
     
  2. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    You can set up an isTrigger collider and when the player walks into it, have it spawn the enemies within that collider. You can use an OnTriggerStay2D() function to detect your enemy spawn zones within the collider and the enemies will appear only while the player remains inside. You can design a file to save enemy states/position and store the information when you leave the collider with OnTriggerExit2D(). Then when you walk back into the collider, access your file and everything will be as it was when you left.
     
  3. SamVorst

    SamVorst

    Joined:
    Nov 28, 2019
    Posts:
    63
    Thanks, i'm gonna try it!
     
    MisterSkitz likes this.
  4. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    Let me know how it works out or if there are any issues you encounter :)