If Box Collider has been hit

So I did some research and found that I needed to create a ray in order to see if a Box Collider has been hit.

In my game I have a cube (controlling the main camera) and a sphere (with a Box Collider).
When my cube touches the sphere I want “Hit” to be displayed in the Console so…

Debug.Log("Hit");

However, I’m not exactly sure that I fully understand the ray/collider code, here is what I did so far:

#pragma strict
var Player: GameObject;

function Update(){
	    var ray : Ray = Player.ScreenPointToRay(Input.mousePosition);
	    var hit : RaycastHit;
	    
	    if (collider.Raycast(ray, hit, 100.0)) {
	        Debug.Log("Hit");
	    }
	}

Hope I can get some useful input, thanks,

Instead of raycasting use

OnCollisionEnter(col : Collision){
    if(col.gameObject.tag == "TagToCollideWith")
        DoSomeLogicHere();
}

You can read about Unitys builtin methods and when are they executed here: