39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
using Cinemachine;
|
|
using EasyInject.Attributes;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// 相机的左右围绕旋转
|
|
/// </summary>
|
|
[GameObjectBean]
|
|
public sealed class CameraRotate : MonoBehaviour
|
|
{
|
|
public float speed = 0;
|
|
[SerializeField]
|
|
private CinemachineVirtualCamera followVirtualCamera;
|
|
|
|
private void Update()
|
|
{
|
|
mouseRoundRoller();
|
|
}
|
|
void mouseRoundRoller()
|
|
{
|
|
//不得当前活动相机返回
|
|
if (!CinemachineCore.Instance.IsLive(followVirtualCamera))
|
|
{
|
|
return;
|
|
}
|
|
if (Input.GetMouseButton(0)) // 检查鼠标左键是否按下
|
|
{
|
|
// 根据鼠标移动量调整旋转角度
|
|
float mouseX = Input.GetAxis("Mouse X") * speed * Time.deltaTime;
|
|
Transform target = followVirtualCamera.LookAt;
|
|
float y = target.rotation.eulerAngles.y;
|
|
y -= mouseX;
|
|
// 应用新的旋转角度
|
|
target.rotation = Quaternion.Euler(0, y, 0);
|
|
//transform.position = transform.position - transform.forward;
|
|
}
|
|
|
|
}
|
|
}
|