如何从触摸板获取鼠标滚动?
How to Get Mouse Scroll from Touchpad?
Input.mouseScrollDelta
仅针对物理鼠标滚轮进行更改。对于触摸板双指滚动手势,它没有变化(尽管滚动图标确实出现并且在其他程序中可以正常工作)。 Input.GetAxis("Mouse ScrollWheel")
具有相同的效果。 Input.touchCount
(或任何与触摸相关的内容)仅适用于触摸屏,无法帮助我在触摸板上进行自己的滚动检查。所以我没主意了。我究竟应该如何知道我正在笔记本电脑的触摸板上滚动?
既然你把它标记为Unity3d,也许这会帮助你克服:https://answers.unity.com/questions/356767/how-to-get-scrollwheel-values-using-a-laptop-touch.html
public void OnGUI()
{
if(Event.current.type == EventType.ScrollWheel)
// do stuff with Event.current.delta
Debug.Log(Event.current.delta);
}
OnGui
文档可在此处找到:https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnGUI.html
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 150, 100), "I am a button"))
{
print("You clicked the button!");
}
}
}
OnGUI is called for rendering and handling GUI events.
This means that your OnGUI implementation might be called several times per frame (one call per event). For more information on GUI events see the Event reference. If the MonoBehaviour's enabled property is set to false, OnGUI() will not be called.
Input.mouseScrollDelta
仅针对物理鼠标滚轮进行更改。对于触摸板双指滚动手势,它没有变化(尽管滚动图标确实出现并且在其他程序中可以正常工作)。 Input.GetAxis("Mouse ScrollWheel")
具有相同的效果。 Input.touchCount
(或任何与触摸相关的内容)仅适用于触摸屏,无法帮助我在触摸板上进行自己的滚动检查。所以我没主意了。我究竟应该如何知道我正在笔记本电脑的触摸板上滚动?
既然你把它标记为Unity3d,也许这会帮助你克服:https://answers.unity.com/questions/356767/how-to-get-scrollwheel-values-using-a-laptop-touch.html
public void OnGUI()
{
if(Event.current.type == EventType.ScrollWheel)
// do stuff with Event.current.delta
Debug.Log(Event.current.delta);
}
OnGui
文档可在此处找到:https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnGUI.html
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 150, 100), "I am a button"))
{
print("You clicked the button!");
}
}
}
OnGUI is called for rendering and handling GUI events.
This means that your OnGUI implementation might be called several times per frame (one call per event). For more information on GUI events see the Event reference. If the MonoBehaviour's enabled property is set to false, OnGUI() will not be called.