注释
在项目中经常会用到名字始终看向相机,可以挂上如下代码
cpp
using UnityEngine;
public class LookAtCamera : MonoBehaviour
{
public Camera _camera;
public void Start()
{
_camera = Camera.main;
}
void Update()
{
//transform.LookAt(transform.position + _camera.transform.rotation * Vector3.forward, _camera.transform.rotation * Vector3.up);
transform.eulerAngles = new Vector3(_camera.transform.eulerAngles.x, _camera.transform.eulerAngles.y, 0);
}
}