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

How to check if there is a certain object on given point?

Discussion in '2D' started by Marioooo, Oct 1, 2018.

  1. Marioooo

    Marioooo

    Joined:
    Sep 20, 2017
    Posts:
    6
    I'm creating a puzzle game and i have a XY coordinate... I need to check if there is a certain type of gameobject. Which function should I use? Should use as an identifier a Tag or a Layer?

    More Info:

    A block is falling, before it does again a need to know if there is an empty space below in order to commit the movement... So i have the actual block coordinate and I want to check the Transform.Position.Y - 1 coordinate... if there is another block, movement is cancelled and block stops. If there is an empty space, block should move... Like Tetris...

    Thanks
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
  3. Marioooo

    Marioooo

    Joined:
    Sep 20, 2017
    Posts:
    6
  4. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    You can try with arrays, store position/block/... in it and check then
     
    Marioooo likes this.
  5. Marioooo

    Marioooo

    Joined:
    Sep 20, 2017
    Posts:
    6
    i think that's the way i'll try first, idk if this is the best way because there is a lot more happening and probably the best way will be using colliders... Thanks a lot!