using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 言灵朝向相机 /// public class YanLingLookAtCamera : MonoBehaviour { private Camera mMainCamera = null; private Vector3 pos = Vector3.zero; // Start is called before the first frame update void Start() { mMainCamera = Camera.main; transform.localPosition = new Vector3(0, 2.5f, 0); } // Update is called once per frame void Update() { mMainCamera = Camera.main; Transform target = mMainCamera.transform; //if (mMainCamera != null) //{ // pos.x = mMainCamera.transform.position.x; // pos.y = mTransform.position.y; // pos.z = mMainCamera.transform.position.z; // mTransform.LookAt(pos); //} var forward = target.TransformDirection(Vector3.forward); //transform.position = target.position + forward * distance; var toward = Quaternion.identity; toward.SetLookRotation(-target.forward, target.up); transform.rotation = toward; } }