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

How to make multiple collision enter

Discussion in 'General Discussion' started by FastMan55, Sep 26, 2021.

  1. FastMan55

    FastMan55

    Joined:
    Jun 8, 2018
    Posts:
    1
    I would like to create a game like a minesweeper. And I ran into a problem while creating the game. How to count nearby bombs? I can create 8 child objects with a collider on an empty slot and place them in all directions to count the bombs, but I think this is a bad solution.btw i am bad at coding.Thank you in advance!
     

    Attached Files:

  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    You can simply make a 2d grid and work without colliders. Then for a given cell you can simply count nearby bombs by looping through 8 nearby cells.

    If you insist on using gridless approach, then call Physics2D.OverlapCircle or Physics2D.OverlapBox https://docs.unity3d.com/ScriptReference/Physics2D.OverlapCircle.html eight times at position of nearby cells, and check if it hits anything, and whether that "anything" is a bomb.
     
    angrypenguin and FastMan55 like this.