Created
August 16, 2019 13:35
-
-
Save ezirmusitua/67bc0bc12073451b56e5ce51225b8e60 to your computer and use it in GitHub Desktop.
[Make Object Always Face To Camera] Use `LookRotation` to make Object always face to camera #unity #rotation
This file contains hidden or 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
// Reference: https://www.cnblogs.com/hejianchun/articles/3108954.html | |
public class HPBar : MonoBehaviour { | |
public GameObject hpBar; // 获取血条信息。 | |
public GameObject camera; // 获取主摄像机 | |
public Vector3 offset; // 血条和人物坐标的差值,也就是血条在人物的上中方...之类的.这样理解 | |
void Update () { | |
Vector3 relativePos = transform.position - camera.transform.position; | |
Quaternion rotation = Quaternion.LookRotation(relativePos); | |
hpBar.transform.rotation = rotation; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment