if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
CinemachineVirtualCamera virtualCamera = cam as CinemachineVirtualCamera;
CinemachineComponentBase body = virtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body);
if (body is not CinemachineFramingTransposer)
{
return;
}
CinemachineFramingTransposer transposer = (body as CinemachineFramingTransposer);
float cameraDistance = transposer.m_CameraDistance;
if (GameUtil.IsPointerOverUI(Input.mousePosition))
{
return;
}
float delta_z = -Input.GetAxis("Mouse ScrollWheel") * ZoomSpeed;
/* if (distance == 0 ||Mathf.Abs(distance-transposer.m_CameraDistance)>10) //后面的逻辑主要是 内外摄像机切换的时候他们两个必定是初始值不一样的,所以当检测到明显的差距那么初始值就重新赋值一下
{
distance = transposer.m_CameraDistance;
}*/
//distance += delta_z;
transposer.m_CameraDistance += delta_z;
}
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
CinemachineVirtualCamera virtualCamera = cam as CinemachineVirtualCamera;
CinemachineComponentBase body = virtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body);
if (body is not CinemachineFramingTransposer)
{
return;
}
CinemachineFramingTransposer transposer = (body as CinemachineFramingTransposer);
float cameraDistance = transposer.m_CameraDistance;
if (GameUtil.IsPointerOverUI(Input.mousePosition))
{
return;
}
float delta_z = -Input.GetAxis("Mouse ScrollWheel") * ZoomSpeed;
/* if (distance == 0 ||Mathf.Abs(distance-transposer.m_CameraDistance)>10) //后面的逻辑主要是 内外摄像机切换的时候他们两个必定是初始值不一样的,所以当检测到明显的差距那么初始值就重新赋值一下
{
distance = transposer.m_CameraDistance;
}*/
//distance += delta_z;
transposer.m_CameraDistance += delta_z;
} if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
CinemachineVirtualCamera virtualCamera = cam as CinemachineVirtualCamera;
CinemachineComponentBase body = virtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body);
if (body is not CinemachineFramingTransposer)
{
return;
}
CinemachineFramingTransposer transposer = (body as CinemachineFramingTransposer);
float cameraDistance = transposer.m_CameraDistance;
if (GameUtil.IsPointerOverUI(Input.mousePosition))
{
return;
}
float delta_z = -Input.GetAxis("Mouse ScrollWheel") * ZoomSpeed;
/* if (distance == 0 ||Mathf.Abs(distance-transposer.m_CameraDistance)>10) //后面的逻辑主要是 内外摄像机切换的时候他们两个必定是初始值不一样的,所以当检测到明显的差距那么初始值就重新赋值一下
{
distance = transposer.m_CameraDistance;
}*/
//distance += delta_z;
transposer.m_CameraDistance += delta_z;
}
如果是非虚拟相机则修改position.z轴就行