unity check if mouse clicked object code example

Example 1: how to detect a mouse click in unity

using UnityEngine;
using System.Collections;

		if (Input.GetMouseButtonDown(0)) {
        	//Left Mouse Button
        } else if (Input.GetMouseButtonDown(1)) {
        	//Right Mouse Button
        } if (Input.GetMouseButtonDown(2)) {
        	//Middle Mouse Button
        }

Example 2: unity if gameobject is clicked

void OnMouseDown() 
 {
   Debug.Log("Mouse is down")
 } 

 void OnMouseUp() 
 {
   Debug.Log("Mouse is up")
 } 

 void OnMouseClick() 
 {
   Debug.Log("Mouse is clicked (down then up its 1 click)")
 } 

// Works only if the gameobject have a collider