[英]How do I Detect if the Mouse is Moving on Screen in Unity?
我正在为我的名为 PROTOTYPE 的游戏制作 360 度摄像机移动。 我需要一个函数或其他东西来检测鼠标是否在移动以及它在 x 轴上的哪个方向,以设置相机平滑脚本的偏移量,但我不知道。 有人可以帮助我吗? 如果需要,这是相机平滑脚本:
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;
void FixedUpdate()
{
Vector3 desiredPosition = target.position + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
transform.LookAt(target);
}
}
我想你想用你的鼠标移动你的相机,围绕你的角色 360° 并且该脚本也附加到你的播放器上。
为此,您的 FixedUpdate 应如下所示:
void FixedUpdate()
{
float horizontalAxis = Input.GetAxis("Mouse X"); // Getting the current mouse axis (left-right)
float verticalAxis = Input.GetAxis("Mouse Y"); // Getting the current mouse axis (up-down)
transform.RotateAround(player.transform.position, -Vector3.up, horizontalAxis * smoothSpeed);
transform.RotateAround(Vector3.zero, transform.right, verticalAxis * smoothSpeed);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.