Esempio n. 1
0
    /**
     * Returns the tile's coordinates that matches the touch input's pixel coordinates
     *
     * returns Vector2(-1, -1) if no candidate tile is found
     */
    private Vector2 GetTilePositionFromTouchInput(Vector2 touchPos)
    {
        for (int i = 0; i < BoxScript.grid.GetLength(0); ++i)
        {
            for (int j = 0; j < BoxScript.grid.GetLength(1); ++j)
            {
                if (BoxScript.grid[i, j] != null)
                {
                    BoxScript boxObj = BoxScript.grid[i, j].gameObject.GetComponent <BoxScript>();

                    if (boxObj.IsInsideTile(touchPos, .92f))
                    {
                        return(new Vector2(i, j));
                    }
                }
            }
        }

        return(new Vector2(-1, -1));
    }