using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; /******************************************************************************** *Create By CG *Function 摄像机环绕某个物体旋转展示 *********************************************************************************/ namespace ZXK.UTility { public class CameraAroundCtrl : MonoBehaviour { /// /// 需要围绕的物体 /// public Transform _CenObj; //private float _disCen; private void Update() { if (!EventSystem.current.IsPointerOverGameObject()) { SetCamDistance(); SetCamRotation(); } } /// /// 设置摄像机距离物体远近 /// private void SetCamDistance() { if(Input.GetAxis("Mouse ScrollWheel") > 0) { transform.Translate(Vector3.forward * 0.5f); } if (Input.GetAxis("Mouse ScrollWheel") < 0) { transform.Translate(Vector3.forward * -0.5f); } } /// /// 设置摄像机围绕物体旋转 /// private void SetCamRotation() { float mouse_x = Input.GetAxis("Mouse X"); float mouse_y = Input.GetAxis("Mouse Y"); if (Input.GetKey(KeyCode.Mouse1)) { transform.RotateAround(_CenObj.position, transform.up, mouse_x * 5); transform.RotateAround(_CenObj.position, transform.right, -mouse_y * 5); } } } }