UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Input.mouseScrollDelta
# [Input](https://docs.unity3d.com/cn/2019.4/ScriptReference/Input.html).mouseScrollDelta public static [Vector2](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector2.html) **mouseScrollDelta** ; ## 描述 当前的鼠标滚动增量。(只读) [Input.mouseScrollDelta](https://docs.unity3d.com/cn/2019.4/ScriptReference/Input-mouseScrollDelta.html) 存储在 [Vector2.y](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector2-y.html) 属性中。([Vector2.x](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector2-x.html) 值将被忽略。)[Input.mouseScrollDelta](https://docs.unity3d.com/cn/2019.4/ScriptReference/Input-mouseScrollDelta.html) 可以是正数(向上)或负数(向下)。未旋转鼠标滚轮时,该值为零。注意,PC 上一般采用带有中心滚轮的鼠标。新版 `macOS` 在触控板上通过双指上下移动来模拟中心滚动。需要根据滚动速率,调整 [mouseScrollDelta](https://docs.unity3d.com/cn/2019.4/ScriptReference/Input-mouseScrollDelta.html) 返回的值。下面的示例中,使用了 `0.1f` 的 `scale`。 注意,[mouseScrollDelta](https://docs.unity3d.com/cn/2019.4/ScriptReference/Input-mouseScrollDelta.html) 为只读。 ``` using System.Collections; using System.Collections.Generic; using UnityEngine; // Input.mouseScrollDelta example // // Create a sphere moved by a mouse scrollwheel or two-finger // slide on a Mac trackpad. public class ExampleClass : MonoBehaviour { private Transform sphere; private float scale; void Awake() { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere = go.transform; // create a yellow quad go = GameObject.CreatePrimitive(PrimitiveType.Quad); go.transform.Rotate(new Vector3(90.0f, 0.0f, 0.0f)); go.transform.localScale = new Vector3(4.0f, 4.0f, 4.0f); go.GetComponent<Renderer>().material.color = new Color(0.75f, 0.75f, 0.0f, 0.5f); // change the camera color and position Camera.main.clearFlags = CameraClearFlags.SolidColor; Camera.main.transform.position = new Vector3(2, 1, 5); Camera.main.transform.Rotate(0, -160, 0); scale = 0.1f; } void OnGUI() { Vector3 pos = sphere.position; pos.y += Input.mouseScrollDelta.y * scale; sphere.position = pos; } } ```
da
2022年6月14日 15:14
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码