Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class XXX : MonoBehaviour
- {
- Plane plane;
- Transform target;
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out RaycastHit hit))
- {
- target = hit.transform;
- plane = new Plane(-ray.direction, target.position);
- }
- }
- else if (target != null && Input.GetMouseButton(0))
- {
- var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (plane.Raycast(ray, out float enter))
- {
- Vector3 hitPoint = ray.GetPoint(enter);
- target.position = hitPoint;
- }
- }
- else if (Input.GetMouseButtonUp(0))
- {
- target = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement