- Home /
Question by
SevenTernGames · Sep 02, 2020 at 08:01 PM ·
mousemouse positionmouseorbit
How can I put range on the mousewheel in three different axis?
public class CameraMovement : MonoBehaviour { public float lookSpeedH = 2f; public float lookSpeedV = 2f; public float zoomSpeed = 2f; public float dragSpeed = 6f;
private float yaw = 0f;
private float pitch = 0f;
public float maxY = 80f;
public float minY = 10f;
public float maxX = 500f;
public float minX = 70f;
public float maxZ = 500f;
public float minZ = 70f;
public float cameraz;
public Vector3 cmrmainposition = new Vector3(500, 500, 275);
public float cameraDistance = 10f;
public float cameraDistanceMin = 5f;
public float cameraDistanceMax = 80f;
float scrollSpeed = .5f;
void Update()
{
Vector3 pos = transform.position;
if (Input.GetMouseButton(1))
{
yaw += lookSpeedH * Input.GetAxis("Mouse X");
pitch -= lookSpeedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0f);
}
if (Input.GetMouseButton(2))
{
cameraDistance += Input.GetAxis("Mouse ScrollWheel") * scrollSpeed;
cameraDistance = Mathf.Clamp(cameraDistance, cameraDistanceMin, cameraDistanceMax);
transform.Translate(-Input.GetAxisRaw("Mouse X") * Time.deltaTime * dragSpeed, -Input.GetAxisRaw("Mouse Y") * Time.deltaTime * dragSpeed, 0);
}
transform.position = pos;
cameraz = Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
transform.Translate(0,0, cameraz , Space.Self);
pos.y = Mathf.Clamp(pos.y, minY, maxY);
pos.x = Mathf.Clamp(pos.x, minX, maxX);
pos.z = Mathf.Clamp(pos.z, minZ, maxZ);
}
}
Comment