Version: 2021.1

Event.mousePosition

切换到手册
public Vector2 mousePosition ;

描述

鼠标位置。

EventType.MouseMoveEventType.MouseDrag 事件中使用。窗口的左上角返回 (0, 0)。右下角返回 (Screen.width, Screen.height)。

另请参阅:Event.delta

using UnityEngine;
using System.Collections;

// print the mousePosition every 10th of a second

public class ExampleClass : MonoBehaviour { private float range = 0.0f;

void OnGUI() { range = range + Time.deltaTime;

if (range > 0.1f) { Event e = Event.current; Debug.Log(e.mousePosition); range = 0.0f; } } }