Drag Object with Mouse – Unity3D (C#) It’s too easy and quick to drag an object with mouse. Just use OnMouseDown() and OnMouseDrag() functions. private Vector3 screenPoint; private Vector3 offset; void OnMouseDown(){ screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position); offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); } void OnMouseDrag(){ Vector3 cursorPoint = new […]
position
Move Object to Mouse Click Position – Unity3D (C#) No matter 2D or 3D, we use same method to move an object to mouse click position. We need to get mouse click position on ground or whatever, and move object to this position. Create a plane and a cube. We […]
