Last active
March 1, 2018 16:46
-
-
Save jeffvella/1482184142dfd202c1b21d5ad9bd0e7f to your computer and use it in GitHub Desktop.
Offset world canvas for perspective camera.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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