Need help script: check if double click is in the same location

I am trying to write a script that wants the player to confirm an action by clicking the same place twice. The thing I tried is to create a raycast on the first click and set a variable that will determine if the click was the first one or not. Then, if the second click is made, another ray is cast. If the rays match, then the player shoots. However, comparing the rays does not work and I don’t understand why. Can anyone help me with this?

function selectTarget(){
	if(Input.GetMouseButtonUp(0)){
		if(timesClicked == 0){
			timesClicked = timesClicked + 1;
			var rayClick : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);    
   			var pointClick : Vector3 = rayClick.origin + (rayClick.direction);   
			
		}
		else{
			var rayClick2 : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);    
   			var pointClick2 : Vector3 = rayClick2.origin + (rayClick2.direction);   
			Debug.Log(pointClick2);
			timesClicked = 0;
			
			        if(pointClick == pointClick2){
				spawnpoint.Shoot();
				}
		}
		
	}

Are you certain that pointClick actually does equal pointClick2? Perhaps there is a very small decimal difference between the two? You could try having some margin of error coded that allows a +/- distance in the x,y and z components of the pointClick vector3s.e.g:

var errorMargin: float = 0.001;
if(Vector3.Distance(pointClick1, pointClick2)) < errorMargin){
     spawnpoint.Shoot();
}

Alternatively you could try something based on time, rather than position, e.g. (credit to DaveA on Unity answers - this code is for a double press of the key “w” to trigger an animation change):

private var lastTapTime = 0;
var tapSpeed = .5; // in seconds, bigger numbers allow more time to detect double-tap
    
function Update(){
    if (Input.GetKeyDown ("w")){
        if ((Time.time - lastTapTime) < tapSpeed){
            changeAnimation();
        }
    lastTapTime = Time.time;
    }
}

Even though double clicking seems counter-intuitive, especially for a game, I would suggest if you want to test double click in a location, you don’t base it off a ray, just do a comparison to the screen X/Y values for the mouse click location, if the second click is within a few pixels, you can fire off the ray then.

The double click is there to confirm the action of the player. I am trying to build a jagged alliance/xcom kind of game where you select a target and get information about how hard it is to hit. If you agree, you click again to fire.

I tried using ROUND to make sure the vectors are the same and the debug tells me that they are, but still it won’t work.

I am using an isometric vies so if I were to use the X/Y values, wouldn’t that give the wrong location?

I found the problem. I was storing the variables inside the function and that doesn’t seem te work very wel. I moved them outside of the function and now it works fine.