using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 相机环绕 /// public class MyCameraRoate : MonoBehaviour { Vector3 center; float speed; float radius; float high; Transform cameraobj; private void Update() { if(cameraobj != null) { cameraobj.RotateAround(center, Vector3.up, Time.deltaTime*speed); cameraobj.LookAt(center); } } public void StartRoate(Camera camera,Vector3 center,float radius,float speed,float high) { this.center = center; this.radius = radius; this.speed = speed; this.high = high; //记录当前位置 Vector3 currentPostion= camera.transform.position; camera.transform.position = center; camera.transform.LookAt(new Vector3(currentPostion.x, center.y, currentPostion.z)); camera.transform.Translate(Vector3.forward * radius+new Vector3(0,high,0), Space.Self); Vector3 startpoint = camera.transform.position; //还原 camera.transform.position = currentPostion; camera.transform.DOMove(startpoint, 2).OnComplete( ()=> { camera.transform.DOLookAt(center, 1).OnComplete(() => { cameraobj = camera.transform; }); }); } public void EndRoate() { cameraobj.DOKill(); cameraobj = null; } }