Skip to content

Instantly share code, notes, and snippets.

@ezirmusitua
Created August 16, 2019 13:35
Show Gist options
  • Save ezirmusitua/67bc0bc12073451b56e5ce51225b8e60 to your computer and use it in GitHub Desktop.
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
// 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