check if button gets clicked unity code example
Example 1: unity check when clicked on object
void Update()
{
// Check for mouse input
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
// Casts the ray and get the first game object hit
Physics.Raycast(ray, out hit);
Debug.Log("This hit at " + hit.point );
}
}
Example 2: if button pressed unity
//There are two ways to do this:
someButton.onClick += someDelegate;
//OR
//you can add the event in the inspector, a video tutorial would work best here