I’m basically a newbie with Unity. I’ve created some simple projects from tutorials but only have basic understanding.
I have a plane in 3D space. I want to click on the plane with the mouse and get the coordinates for that click (i.e. whereabouts on the plane I clicked) .
Currently I can only get the world coordinates on-click. I tried getting the position of the plane in world space so that I can convert my mouse click coordinates to plane coordinates but this doesn’t do what I expected and actually gives me the coordinates on plane relative to the transform associate with my player script. I feel like there may be a better way to do this anyway.
Here is my simplified PlayerMovement script:
public class PlayerMovement : MonoBehaviour {
// Use this for initialization
void Start () {
plane = GetComponent(typeof(MeshFilter)) as MeshFilter;
}
void Update() {
if (Input.GetMouseButtonDown (0)) {
Debug.Log ("mouseDown = " + Input.mousePosition.x + " " + Input.mousePosition.y);
Debug.Log ("position in plane = " + plane.transform.position);
}
}
}
I’d really appreciate any pointers here.
I imagine it’s simple enough when you know how. I have looked at quite a few articles and pieces of documentation but I just can’t find a solution.
Thanks in advance.