using UnityEngine;
public class FreeCamera : MonoBehaviour
{
public float lookSpeedH = 2f;
public float lookSpeedV = 2f;
public float zoomSpeed = 20f;
public float dragSpeed = 100f;
private float yaw = 0f;
private float pitch = 0f;
void Update()
{
//Look around with Right Mouse
if (Input.GetMouseButton(1))
{
yaw += lookSpeedH * Input.GetAxis("Mouse X");
pitch -= lookSpeedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0f);
}
//drag camera around with Middle Mouse
if (Input.GetMouseButton(2))
{
transform.Translate(-Input.GetAxisRaw("Mouse X") * Time.deltaTime * dragSpeed, -Input.GetAxisRaw("Mouse Y") * Time.deltaTime * dragSpeed, 0);
}
//Zoom in and out with Mouse Wheel
transform.Translate(0, 0, Input.GetAxis("Mouse ScrollWheel") * zoomSpeed, Space.Self);
}
}
Unity 像在Game里面移动摄像机 平移旋转缩放
最新推荐文章于 2023-03-21 20:21:26 发布