using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FollowCamera : MonoBehaviour
{
//主摄像机对象
private Camera _camera;
public bool isBack = false;
void Start()
{
_camera = Camera.main;
}
private void Update()
{
// 物体始终面向摄像机
if (_camera == null) return;
var rotation = Quaternion.LookRotation(_camera.transform.TransformVector(isBack?Vector3.back : Vector3.forward),
_camera.transform.TransformVector(Vector3.up));
rotation = new Quaternion(0, rotation.y, 0, rotation.w);
gameObject.transform.rotation = rotation;
}
}