Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


mousePosition

The mouse position.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Property
  • Namespace: UnityEngine
  • Assembly: UnityEngine.IMGUIModule
public Vector2 mousePosition { get; set; }

Remarks

Used in EventType.MouseMove and EventType.MouseDrag events. The top-left of the window returns (0, 0). The bottom-right returns (Screen.width, Screen.height).
Additional Resources: Event.delta.

Examples

using UnityEngine;using System.Collections;// print the mousePosition every 10th of a secondpublic 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; } }}