unity实现⽤⿏标右键控制摄像机视⾓上下左右移动using System;
using System.Collections.Generic;
using UnityEngine;
public class ViewControl
{
enum RotationAxes
{
MouseXAndY,
MouseX,
MouseY
}
RotationAxes axes = RotationAxes.MouseXAndY;
float sensitivityX = 10;
float sensitivityY = 10;
float minimumY = -45;
float maximumY = 45;
private float rotationY = 0;
public void Update()
{
if (Input.GetMouseButton(0))
{鼠标右键不能用
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = ansform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX; rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
ansform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
ansform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
ansform.localEulerAngles = new Vector3(-rotationY,
ansform.localEulerAngles.y, 0);
}
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论