Need to Find Distance Between Mouse Cursor and Object in a 2.5D SideScroller

I’m totally new to Unity though I’ve been coding a bit and I’ve made some stuff in GameMaker. Anyways I’ve been working on the basic stuff for a 2.5D sidescroller and I’m having trouble with refining the camera. The cursor will move independent of the camera, but WILL extend the camera somewhat subtly if pushed near the edge. I’m also trying to get the camera to extend to the left or the right of the character depending on which direction the character is facing. I’ve got basic camera movement and camera boundaries relative to the character. I just need help with subtle camera movements and set ups based on the cursor in relation to the character (i.e. a cursor to the right of a character means he’s facing that direction and would have the camera extend that direction). I’m having trouble properly measuring the distance between the cursor and the character.

To my understanding, “Raycasts” might be the best way to figure this out, but after messing with them a while I’m quite lost on them. I’m not really good with coding and I’m used to C++ so I’ve been using C#. It’d be awesome for anyone to get back to me!

The simplest method of making the conversion is to use Camera.ScreenToWorldPoint(). As a starting point, you will need to provide or calculate the distance between the camera and the plane you are using for your 2D movements. The code would then be something like this (assumes the camera is looking towards positive ‘Z’):

Vector3 v3Pos = new Vector3(Input.mousePosition.x Input.mousePosition.y, distance);
v3Pos = Camera.main.ScreenToWorldPoint(v3Pos);

v3Pos = v3Pos - character.position;

if (v3Pos.x > 0.0f) 
    Debug.Log("Cursor is in front of the character");
    Debug.Log("Cursor is behind the character");