|
|
@@ -0,0 +1,24 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+public class AlwaysFaceCamera : MonoBehaviour
|
|
|
+{
|
|
|
+ private Transform mainCam;
|
|
|
+ public float rotateRate = 5;
|
|
|
+
|
|
|
+ private void Start()
|
|
|
+ {
|
|
|
+ mainCam = Camera.main.transform;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Update()
|
|
|
+ {
|
|
|
+ Vector3 vec = mainCam.position - transform.position;
|
|
|
+ transform.LookAt(mainCam.position - vec * rotateRate);
|
|
|
+ Vector3 v = transform.localEulerAngles;
|
|
|
+ v.x = 0;
|
|
|
+ v.z = 0;
|
|
|
+ transform.localEulerAngles = v;
|
|
|
+ }
|
|
|
+}
|