其他分享
首页 > 其他分享> > Unity人员始终面对摄像机

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;
    }

}

标签:Vector3,始终,transform,摄像机,Unity,camera,using,rotation
来源: https://www.cnblogs.com/skyvip/p/15709419.html