Updated Question if statement not executing case

I’m trying a different approach. The Raycasting was simply not working, so I tagged the FPController as Player and tried it this way. I reset the max distance to 8.5f since you can never get to 2.0 even if you are right on top of the chest. While I get the distance, the case statement won’t execute. I’m guessing because of the return, but I’m not sure how to make them both happy.
In Start() I’m setting the variable-
Player= GameObject.FindGameObjectWithTag(“Player”);
if(Player==null)
Debug.Log(“Could not find Main Camera”);

public void OnMouseUp(){
	Debug.Log("Mouse Up");

		 		if(Vector3.Distance(transform.position, Player.transform.position)>maxDistance)
		Debug.Log("You need to be closer!");
		Debug.Log(Vector3.Distance(transform.position, Player.transform.position));		
	return;
	if(Vector3.Distance(transform.position, Player.transform.position)<=maxDistance)

	switch(state){
		case ChestState.open:
		state=ChestState.inbetween;
		StartCoroutine("CloseChest");
		break;
	
		case ChestState.closed: 
			StartCoroutine("OpenChest");
		break;
		}
	}
Thoughts? Anyone?

I think you need braces around those Debug.Log statements - I presume that you were intending to do that logging and return if the distance was too far away - but the way the code reads now it will only use the If for the first debug.log. The second debug.log will always happen and then it will always return.

Here’s the code you should use - you also don’t need the second if.

public void OnMouseUp()
{
    Debug.Log("Mouse Up");

   if(Vector3.Distance(transform.position, Player.transform.position)>maxDistance) 
   {
       Debug.Log("You need to be closer!");
       Debug.Log(Vector3.Distance(transform.position, Player.transform.position));     
      return;
   }

   switch(state)
   {
       case ChestState.open:
           state=ChestState.inbetween;
           StartCoroutine("CloseChest");
           break;

       case ChestState.closed: 
           StartCoroutine("OpenChest");
           break;
   }
}