Unity人员始终面对摄像机

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UserC : MonoBehaviour
{
    //主摄像机对象
    private new Camera camera;

    void Start()
    {
        camera = Camera.main;
    }

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

}

上一篇:Unity动画系统学习方向


下一篇:Unity基础知识、Transform类