Version: 2022.3
LanguageEnglish
  • C#

EventType

enumeration

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Types of UnityGUI input and processing events.

Use this to tell which type of event has taken place in the GUI. Types of Events include mouse clicking, mouse dragging, button pressing, the mouse entering or exiting the window, and the scroll wheel as well as others mentioned below.

Events can be used to prevent other GUI elements from responding to that event. Refer to Event.Use.

Additional resources: Event.type, Event, GUI Scripting Guide.

//Attach this script to a GameObject
//This script is a basic overview of some of the Event Types available. It outputs messages depending on the current Event Type.

using UnityEngine;

public class Example : MonoBehaviour { void OnGUI() { Event m_Event = Event.current;

if (m_Event.type == EventType.MouseDown) { Debug.Log("Mouse Down."); }

if (m_Event.type == EventType.MouseDrag) { Debug.Log("Mouse Dragged."); }

if (m_Event.type == EventType.MouseUp) { Debug.Log("Mouse Up."); } } }
using UnityEngine;

public class Example : MonoBehaviour { void OnGUI() { Event m_Event = Event.current;

if (m_Event.type == EventType.MouseDown) { if (m_Event.pointerType == PointerType.Pen) //Check if it's a pen event. Debug.Log("Pen Down."); else Debug.Log("Mouse Down.");         //If it's not a pen event, it's a mouse event. } } }

Properties

MouseDownMouse button was pressed.
MouseUpMouse button was released.
MouseMoveMouse was moved (Editor views only).
MouseDragMouse was dragged.
KeyDownA keyboard key was pressed.
KeyUpA keyboard key was released.
ScrollWheelThe scroll wheel was moved.
RepaintA repaint event. One is sent every frame.
LayoutA layout event.
DragUpdatedEditor only: drag & drop operation updated.
DragPerformEditor only: drag & drop operation performed.
DragExitedEditor only: drag & drop operation exited.
Ignore Event should be ignored.
UsedAlready processed event.
ValidateCommandValidates a special command (e.g. copy & paste).
ExecuteCommandExecute a special command (eg. copy & paste).
ContextClickUser has right-clicked (or control-clicked on the mac).
MouseEnterWindowMouse entered a window (Editor views only).
MouseLeaveWindowMouse left a window (Editor views only).
TouchDownDirect manipulation device (finger, pen) touched the screen.
TouchUpDirect manipulation device (finger, pen) left the screen.
TouchMoveDirect manipulation device (finger, pen) moved on the screen (drag).
TouchEnterDirect manipulation device (finger, pen) moving into the window (drag).
TouchLeaveDirect manipulation device (finger, pen) moved out of the window (drag).
TouchStationaryDirect manipulation device (finger, pen) stationary event (long touch down).
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961