Skip to content

Instantly share code, notes, and snippets.

@brunomikoski
Created January 15, 2016 08:46
Show Gist options
  • Save brunomikoski/2390caa2f2e6957b97ff to your computer and use it in GitHub Desktop.
Save brunomikoski/2390caa2f2e6957b97ff to your computer and use it in GitHub Desktop.
/// <summary>
/// Returns a position on the edge of the screen
/// </summary>
/// <param name="horizontal">0 being left, and 1 being right</param>
/// <param name="vertical">0 being botton, and 1 being top of the screen</param>
/// <param name="horizontalPadding">Padding from the screen, 0 means on screen, and 0.1 will be 10% off the screen</param>
/// <param name="verticalPadding"> </param>
/// <returns></returns>
public Vector3 GetOffScreenPosition(float horizontal,
float vertical,
float horizontalPadding,
float verticalPadding)
{
Vector3 screenPoint = gameCamera.WorldToViewportPoint(new Vector3(0, 0, 0));
screenPoint.x = horizontal + horizontalPadding;
screenPoint.y = vertical + verticalPadding;
return gameCamera.ViewportToWorldPoint(screenPoint);
}
public Vector3 GetOffScreenPosition(Vector2 initialPosition, Vector2 padding)
{
return GetOffScreenPosition(Mathf.Clamp01(initialPosition.x),
Mathf.Clamp01(initialPosition.y),
Mathf.Clamp01(padding.x),
Mathf.Clamp01(padding.y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment