help
Root Question Message
public void FlipBoard()
{
foreach (var boardObject in _placedObjects)
{
if (boardObject.buildable.Category == LevelEditorCategory.BoardTile || boardObject.buildable.Category == LevelEditorCategory.Piece || boardObject.buildable.Category == LevelEditorCategory.ActionTile)
{
var pos = boardObject.Position;
var newRotation = new Vector2(pos.x, pos.y);
newRotation = newRotation.Rotate(180);
newRotation.x += _levelBounds.max.x;
newRotation.y += _levelBounds.max.y;
boardObject.transform.position = newRotation;
boardObject.Position = new Vector2Int((int)newRotation.x, (int)newRotation.y);
}
}
isFlipped = !isFlipped;
}
public static Vector2 Rotate(this Vector2 v, float degrees)
{
return v.RotateRadians(degrees * Mathf.Deg2Rad);
}
public static Vector2 RotateRadians(this Vector2 v, float radians)
{
var ca = Mathf.Cos(radians);
var sa = Mathf.Sin(radians);
return new Vector2(ca * v.x - sa * v.y, sa * v.x + ca * v.y);
}
var pos = boardObject.Position;
var distanceToEdge = _levelBounds.max.y - pos.y;
pos.y = (int)distanceToEdge;