I want to click on a plane, and get the coordinates of the point on the plane that I clicked.
2 Answers
2If you are using Unity Script then you can do it like this:
var hit : RaycastHit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, 1000) {
var localHit = transform.InverseTransformPoint(hit.point);
//Do something with the local coordinates
}
This will give you the hit point in terms of the plane’s coordinate system.
You need to do a regular ray cast. This will give you the position on the plane you clicked on with your mouse in world coordinates.
You can also use Camera.main.ScreenPointToRay() like here: http://answers.unity3d.com/questions/13577/using-raycast-to-get-mouse-input.html
Take a look at the [Barycentric Coordinates][1]. Alternatively you can just use the [Point][2] parameter and calculate it yourself, knowing the size of the plane, it's orientation, and it's position in the world. [1]:http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-barycentricCoordinate.html [2]:http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-point.html
– asafsitner