How to click on an object

I want to click on a 3D object but I get no respond from the debug log meaning that I am doing something wrong. Here is the code that I am working on.

        if (Input.GetMouseButtonDown(0))
        {
            var hit = new RaycastHit();
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            var select = GameObject.FindWithTag("PlayerCube").transform;
            if (Physics.Raycast (ray, out hit, 100))
            {
                Debug.Log("You hit your first object");
            }
        }

Can anyone figure what it is I am doing wrong? Thanks in advance!

I’d declare my ray and hit variables outside of my function. Place your ray definition inside of Update function so you can check the mouse position every frame. I also usually check the ray using Physics.Raycast before checking for Mouse Button Down event. Be sure you have a collider attached to the object you’re clicking on. You can determine the tag of the object by checking tag of any collider that is clicked. If the tag is equal to the desired string, place your code in the appropriate if statement in this case. You can use an else statement if you wish to do something else if the tag is not as desired.

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{
	Ray ray;
	RaycastHit hit;

	void Update()
	{
		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		if(Physics.Raycast (ray, out hit) && Input.GetMouseButtonDown(0))
		{
			//Object you wish to click must have a collider attached.
			if(hit.collider.tag == "PlayerCube")
				print (hit.collider.name);
			else
				print ("Object is not tagged with 'PlayerCube'");
		}
	}
}