- Home /
Duplicate Question
Mouse Pointer Transform.Position?
Hi everyone, does Unity keep track of where the mouse pointer is? I want to use my mouse pointer's transform position as the beginning point of a spherecast.But I'm not sure how.
if(Physics.SphereCast(//mousepointer.transform.position, 1f, gameObject.transform.forward, out hit, Distance))
Answer by fafase · May 10, 2013 at 06:06 AM
Input.mousePosition
is what you are looking for but it will probably won't do what you are expecting. The position is based on the screen position, so if your screen is 800*640 you won't get anything bigger or smaller than that. Also, it returns a Vector3 which is indeed a Vector2 with a 0 for z -> Vector3
You may want to look at http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenToWorldPoint.html for how to convert the mouse position on screen to world position.
Follow this Question
Related Questions
Rotating a Sphere with the mouse? 1 Answer
Snap Back? 1 Answer
C# Gameobject Rigidbody Mouse Collision 1 Answer
Move mouse to a position on screen? 3 Answers
C# locking Main Camera's Rotations 1 Answer