Unity 物体始终正对摄像机

using UnityEngine;

public class Text3DController : MonoBehaviour
{
    private GameObject _mainCamera;

    // Start is called before the first frame update
    private void Start()
    {
        _mainCamera = GameObject.FindWithTag("MainCamera");
    }

    // Update is called once per frame
    private void Update()
    {
        //物体始终面向摄像机
        var rotation = Quaternion.LookRotation(_mainCamera.transform.TransformVector(Vector3.forward),
            _mainCamera.transform.TransformVector(Vector3.up));
        rotation = new Quaternion(0, rotation.y, 0, rotation.w);
        gameObject.transform.rotation = rotation;
    }
}

脚本挂在需要面向摄像机的物体上即可

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页