Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.8 kB
3
Indexable
Never
private bool IsPositionInsideTilemap(Vector3 position)
    {
        if (dungeonManager != null)
        {
            // Get the current room from dungeonManager
            GameObject currentRoom = dungeonManager.ReturnCurrentRoom();
            if (currentRoom != null)
            {
                Transform roomColliderTransform = FindChildRecursive(currentRoom.transform, "RoomCollider");
                if (roomColliderTransform != null)
                {
                    // Find the TilemapCollider2D within the current room
                    TilemapCollider2D tilemapCollider = roomColliderTransform.GetComponent<TilemapCollider2D>();
                    if (tilemapCollider != null)
                    {
                        // Ensure the position is on the same plane as the 2D physics
                        Vector2 point = new Vector2(position.x, position.y);

                        bool isInside = tilemapCollider.OverlapPoint(point);

                        Debug.Log("tilemapCollider.OverlapPoint(point): " + isInside);
                        Debug.Log("POSITION: " + point);
                        return isInside;
                    }
                    else
                    {
                        Debug.LogError("TilemapCollider2D not found in the current room.");
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            else
            {
                Debug.LogError("Current room is null.");
                return false;
            }
        }
        else
        {
            Debug.LogError("DungeonManager is null.");
            return false;
        }
    }
Leave a Comment