# ScreenPointToRay return question

**URL:** https://discussions.unity.com/t/screenpointtoray-return-question/414110
**Category:** Scripting
**Tags:** Scripting
**Created:** [May 19, 2010, 2:51pm UTC](https://discussions.unity.com/t/screenpointtoray-return-question/414110 "2010-05-19T14:51:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![spoonshoe](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/spoonshoe/32/123314_2.png) [@spoonshoe](https://discussions.unity.com/u/spoonshoe)
#### Post date: [May 19, 2010, 2:51pm UTC](https://discussions.unity.com/t/screenpointtoray-return-question/414110/1 "2010-05-19T14:51:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![anon\_71841649](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@anon\_71841649](https://discussions.unity.com/u/anon_71841649)
#### Post date: [May 19, 2010, 2:57pm UTC](https://discussions.unity.com/t/screenpointtoray-return-question/414110/2 "2010-05-19T14:57:52Z")

</div>

in the second log you print out the ray and not the point where it hit the object. use hit.point instead. they won’t print the exact same numbers though, the second one will print the point where the ray hits the collider and the first one prints the coordinates of pivot of the object it hit

---

<div class="post-metadata">

### Author: ![spoonshoe](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/spoonshoe/32/123314_2.png) [@spoonshoe](https://discussions.unity.com/u/spoonshoe)
#### Post date: [May 19, 2010, 6:00pm UTC](https://discussions.unity.com/t/screenpointtoray-return-question/414110/3 "2010-05-19T18:00:05Z")

</div>

Thanks! Got it now, thanks for your help.
