Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EventSystem.IsPointerOverGameObject

Switch to Manual
public function IsPointerOverGameObject(): bool;
public function IsPointerOverGameObject(pointerId: int): bool;

Parameters

pointerIdPointer (touch / mouse) id.

Description

Is the pointer with the given id over an EventSystem object?

function Update()
	{
		if(Input.GetMouseButtonDown(0))
		{
			if(!EventSystems.EventSystem.current.IsPointerOverGameObject())
			{
				Debug.Log("Did not Click on the UI");
			}
		}
	}

Note on C# that they will need to add "using UnityEngine.EventSystems;" Note that with C# you will need to add "using UnityEngine.EventSystems;".