Answers for "unity 2d on button click"

C#
3

unity click on 2d object

// Requires for the object to have a collider and this script attached
private void OnMouseDown()
{
	Debug.Log("Clicked on object!");
}
Posted by: Guest on October-08-2021
0

get object clicked unity 2d

RaycastHit2D hit = Physics2D.Raycast(Input.mousePosition, Vector2.zero);
if (hit.collider != null)
{
	Debug.Log("Clicked on Object!");
}
Posted by: Guest on April-16-2022

C# Answers by Framework

Browse Popular Code Answers by Language