Search Unity

Destroy 2 GameObject when Overlap

Discussion in 'Getting Started' started by sulaimankhan21, Jul 4, 2017.

  1. sulaimankhan21

    sulaimankhan21

    Joined:
    Jul 2, 2017
    Posts:
    4
    Hello guys I am working on 2D game and I want to destroy 2 GameObjects when they overlap and also player tap on then at that time. I did everything but i don;t have any solution for that. I need your help.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Break this into smaller problems that are easier to tackle:
    • How to tell when the user taps on an object? (There are various ways to do this, all involving a Collider2D and some involving a Physics2D.Raycast.)
    • How to tell when two objects overlap? (Again you'll probably use Physics2D, though if your objects are roughly circular it might suffice to just check the distance between them.)
    • How to destroy the objects? (Object.Destroy or Object.DestroyImmediate.)
    Tackle these one at a time, and let us know if you get stuck!
     
    Kiwasi likes this.