Skip to content

Instantly share code, notes, and snippets.

@jeffvella
Last active March 1, 2018 16:46
Show Gist options
  • Save jeffvella/1482184142dfd202c1b21d5ad9bd0e7f to your computer and use it in GitHub Desktop.
Save jeffvella/1482184142dfd202c1b21d5ad9bd0e7f to your computer and use it in GitHub Desktop.
Offset world canvas for perspective camera.
/// <summary>
/// Counteract the perspective camera effects and place healthbar on top of enemey
/// </summary>
private void FixHealthPosition()
{
var screenHealthBarPosition = Camera.main.WorldToScreenPoint(HealthBarCanvas.transform.position);
var screenEnemyPosition = Camera.main.WorldToScreenPoint(transform.position);
HealthContainer.rectTransform.anchoredPosition = new Vector2(screenEnemyPosition.x - screenHealthBarPosition.x, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment