小编Red*_*edi的帖子

使用 Unity 的新输入系统检测鼠标滚轮滚动输入

我目前正在尝试检测我当前在 Unity 引擎中进行的 2D 游戏的鼠标滚轮滚动输入。

我正在使用新的输入系统,目前我仍坚持使用以下代码。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem.Controls;

public class ZoomController : MonoBehaviour
{

private PlayerControls playerControls;

private void Awake()
{
    playerControls = new PlayerControls();
}


private void OnEnable()
{
    playerControls.Enable();
}

private void OnDisable()
{
    playerControls.Disable();
}

void Start()
{
    
}

void Update()
{

    if (playerControls.Land.Zoom.ReadValue<Vector2>().y >= 1)
    {
        Debug.Log("Scroll 1");
    } else if (playerControls.Land.Zoom.ReadValue<Vector2>().y <= -1)
    {
        Debug.Log("Scroll 2");
    }
    
 }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如果我运行代码,什么也不会发生,我也不知道为什么。

c# user-input input mousewheel unity-game-engine

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

input ×1

mousewheel ×1

unity-game-engine ×1

user-input ×1