Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NPSF3000 - NPSF3001 randomgarbage gmail
- // Free for personal/educational use - all risk is assumed by user.
- // Attribution is nice :P
- Vector3 GetMousePointInWorld_ZAxis()
- {
- // This is quite simple:
- // 1) Get a ray from the mouse,
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- // 2) Intersect with a 'plane' (i.e find out where my mouse ray is when it intersects the z axis as defined by our object),
- Plane plane = new Plane(new Vector3(0, 0, 1), transform.position);
- float distance;
- plane.Raycast(ray, out distance);
- // 3) Return the point.
- return ray.GetPoint(distance);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement