Hello,
New to Unity, not to programming though. I’ve been working on a simple game and I’m having problems with getting the mouse position using ScreenPointToRay. Basically I have a sidescroller, and I have a cube that I want to move to wherever you user clicks.
The code I’m using is below.
public var thiscamera: Camera;
if (Input.GetMouseButton(0))
{
var ray: Ray = thiscamera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit;
if (Physics.Raycast(ray, hit))
{
if (hit.transform == target1)
{
print(“Hit target 1”);
Debug.Log(hit.transform.position);
Debug.Log(“Screen” + thiscamera.main.ScreenPointToRay(Input.mousePosition));
}
}
}
The problem I’m having is that, shouldn’t the Logs spit out the same number? Since I’m printing the position of the cube, and the position of the mouse when I click on the cube? It basically just gives me the camera position again?
Any help would be greatly appreciated.
Thanks