I am trying to get reference of the object underneath my Player.
I don't know if I am approaching this correctly. Right now, I have a player simply put in the scene, like this:
Then I am trying to get reference of it like this (does not work)
public void CheckTileUnder()
{
Vector3 halfExtents = new Vector3(0f, -1 / 2.0f, 0f);
Collider[] colliders = Physics.OverlapBox(transform.position, halfExtents);
foreach (Collider item in colliders)
{
Tile tile = item.GetComponent<Tile>();
if (tile != null)
{
RaycastHit hit;
if (Physics.Raycast(tile.transform.position, Vector3.down, out hit, 1))
{
currentTile = tile;
}
}
}
}
Another approach that I thought of would be to put the player under the Tile like this: Then I guess I would have to change parents like suggested in one of the answers here?
How should I select the Tile under the Player?