How to get exactly position of mouse in a gameObject when it's over it?
I want the exactly position of the mousein World Space when it's over a GameObject, not the position of the GameObject center, but the Vector3 of the point that the mouse touches the GameObject in the World Space. I've tried somethings from raycast that I found in the web unsuccessfully. I expect you have understood my question. Thanks.
Please clarify: do you mean you need the world position of where you touch the GameObject in world space, or the screen position of the mouse pointer?
The world position where I touch the GameObject.
Answer by bubzy · Jan 07, 2016 at 11:15 PM
http://docs.unity3d.com/ScriptReference/RaycastHit-point.html
this will give you the point of an object where the mouse is hitting it
the mouse coordinates are a vector2 though
your question isnt 100% clear about what data you are trying to capture.
I can't figure how just by the documentation example. Please give me more details.
As per the example:
using UnityEngine;
using System.Collections;
public class ExampleClass : $$anonymous$$onoBehaviour {
public float pokeForce;
void Update() {
if (Input.Get$$anonymous$$ouseButtonDown(0)) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
if (hit.rigidbody != null)
//print (GameObject.Transform); // print co-ordinates (or something along those lines)
}
}
}
Your answer
Follow this Question
Related Questions
onmouse over UI pop up help please 0 Answers
User Layer that Ignores Raycast? 2 Answers
Using Physics.Raycast on a 3D object blocks the UI Raycaster from responding! 0 Answers
adding range onto 2d raycast 3 Answers
Line of Sight and Raycasting 0 Answers