Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
Detect Mouse Wheel Scrolling Input with Unity`s new Input System

I'm currently trying to detect the mouse wheel scrolling input for my 2D Game I am currently doing in the Unity Engine.

I'm using the new Input System and I'm currently stuck with the follwing code.

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");
    }
    
 }
}

enter image description here

If I run the code nothing happens and I don't know why.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If you treat the scroll wheel as a "1D Axis" you need to tell Unity which side (up or down) should win. Otherwise, you will only receive an average value which will always be 0.

Action as 1D Axis - tell Unity which side wins

Another option that is better would be to let the value pass through and add a "Binding". enter image description here

enter image description here

Note that the default scroll value is 120 on most systems, but on Linux it seems to be 1. I would therefore recommend simply checking if the value is larger or smaller than 0 to decide if it is scrolling up or down.

float z = zoom.ReadValue<float>();
if (z > 0)
    Debug.Log("Scroll UP");
else if (z < 0)
    Debug.Log("Scroll DOWN");
over 4 years ago · Santiago Trujillo Report

0

Using code alone you can do this:


    Vector2 vec = Mouse.current.scroll.ReadValue();
    scroll = vec.y
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!