click an Object with crosshair

Hi everyboby,

i got a gui crosshair in the middle of the screen and i have hide/locked the mouse cursor using

Screen.lockCursor = true; ( has i am in webplayer the cursor is automaticly hide )

My camera is an third person view with orbitScript.

i have a cyllinder in front of my caracter and i put this script in cyllinder

public bool testEloignement(){
if( target.transform.position.x < transform.position.x + 2 && target.transform.position.x > transform.position.x - 2){
   if(target.transform.position.z < transform.position.z + 2 && target.transform.position.z > transform.position.z - 2){
     return true; 
   }else
     return false;
}else  
   return false;}

and

void OnMouseOver(){
if(Input.GetMouseButtonDown(0) && testEloignement()){
   Debug.Log("clic");
}
Debug.Log("over");

}

But this works only if my cyllinder is between my caracter and the center of the screen.

I have try also to use raycast but maybe not in good way. Cause it do the same a OnMouseOver()

how can i do to clic on it in the frontside ?`

This will cast a ray directly in front of your cylinder, make sure the cylinder’s Z Axis is facing forward, Y axis is facing up, and X axis left /right. Raycast casts a ray out from the Z Axis, or Vector3.Forward. This script will show bullseye!!! in Debug.log when you shoot something by left mouse click.

function Update()
{

var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;

if (Physics.Raycast (transform.position, direction, hit, 1000))
{
         if(Input.GetMouseButtonDown(0))
              {
                   Debug.Log("Bullseye!!!");
              }
    }

}