Is there another way to detect mouse scroll in game for macOS?
Hello, I was trying to use Input.mouseScrollDelta to check if a user scrolled up, down, left or right to check the direction of a gesture on both the Magic Mouse and macOS track pad. Everything seemed to work fine, however, it seems as if the Input.mouseScrollDelta is not designed to work with such devices. The main problem I am facing is that the Input.mouseScrollDelta works by PC mouse scroll wheel clicks, one click equals one input. Every swipe on the Mac counts as many as 8 to 200 scroll wheel clicks for the equivalent PC mouse scroll wheel. The only way to stop this from happening is to let the scroll fully stop registering as input and then re-enable to capture more inputs. The problem is that I need the input to be very quick so that it can capture more directional swipe inputs. Currently it takes a full 2 seconds to stop registering input, even from a very light scroll. This won't work for what I am trying to achieve and I was wondering if there is any other way to go about this problem. I have also tried to adjust the values in the if statements, however, this still does not fix the problem. Thank you for your time.
// block the input from getting called multiple times, re-enable after Vector2.zero
private bool isReset = true;
public void OnGUI()
{
MouseInputMethod();
}
void MouseInputMethod()
{
if (isReset == true)
{
if (Input.mouseScrollDelta.y > 1f)
{
Debug.Log($"DOWN");
isReset = false;
StartCoroutine(ResetZero());
}
if (Input.mouseScrollDelta.y < -1f)
{
Debug.Log($"UP");
isReset = false;
StartCoroutine(ResetZero());
}
if (Input.mouseScrollDelta.x > 1)
{
//Debug.Log($"RIGHT");
isReset = false;
StartCoroutine(ResetZero());
}
if (Input.mouseScrollDelta.x < -1f)
{
//Debug.Log($"LEFT");
isReset = false;
StartCoroutine(ResetZero());
}
}
}
IEnumerator ResetZero()
{
// wait until the vectors have returned to 0
while (Input.mouseScrollDelta != Vector2.zero)
{
// wait a frame to make sure that the input is the final scoll click
yield return new WaitForEndOfFrame();
// check to see if this is the final scroll click
if (Input.mouseScrollDelta == Vector2.zero)
{
// wait one more frame
yield return new WaitForEndOfFrame();
// check once more to make sure that this is the final scroll click
if (Input.mouseScrollDelta == Vector2.zero)
{
// reset the isReset to true so the input can continue to be read
isReset = true;
// break out
break;
}
else
{
// if there is more clicks left continue the while statement
continue;
}
}
}
}
Answer by egeunlu · Jan 06, 2021 at 03:35 AM
I have the same problem with WebGL unity, there are two suspicious properties in standalone input module, 'input actions per second' and 'repeat delay', I have increased the first field up to 1000 but no changes so far.
What are you specifically trying to do? Just capture Directional swipe movements?
Yeah, horizontals for movement and verticals for a custom scrollview.
If you are doing a scroll view try this?
public float yVector = 0;
public float xVector = 0;
public float distance$$anonymous$$ultiplier = 1f;
void Update()
{
if (Input.mouseScrollDelta != Vector2.zero)
{
if (Input.mouseScrollDelta.y > .01f)
{
yVector += 1f * distance$$anonymous$$ultiplier;
Debug.Log($"SWIPE DOWN : {yVector}");
}
if (Input.mouseScrollDelta.y < -.01f)
{
yVector -= 1f * distance$$anonymous$$ultiplier;
Debug.Log($"SWIPE UP : {yVector}");
}
if (Input.mouseScrollDelta.x > .01f)
{
xVector += 1f * distance$$anonymous$$ultiplier;
Debug.Log($"SWIPE RIGHT : {xVector}");
}
if (Input.mouseScrollDelta.x < -.01f)
{
xVector -= 1f * distance$$anonymous$$ultiplier;
Debug.Log($"SWIPE LEFT : {xVector}");
}
}
}
Your answer
Follow this Question
Related Questions
Java to C# Translation 1 Answer
Dropdown list scrollwheel - Camera zoom scrollwheel how can separate? 0 Answers
Input.GetKey Shift Key disbles GetAxis Mouse ScrollWheel? 1 Answer
Why is laptop Touchpad two finger scolling not working on scrollrect in unity game? 0 Answers
input.getkey keycode scrollwheel - Is this even possible? 0 Answers