unity 2d Drag object
private Vector2 screenPoint;
private Vector3 offset;
void OnMouseDown() {
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
}
void OnMouseDrag()
{
Vector2 curScreenPoint = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector2 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
Also in C#:
- unity movetowards 2d
- c# tostring mmm dd yyyy
- get setter c# model
- c# EncoderParameter
- modal dismiss
- how to turn a string in a char list c#
- c# stop loop in method
- scaffold-dbcontext sql server
- autofixture ignore property
- unity main texture not working
- c# multiline comment
- unity access child
- phone
- unity vector3 to array
- unity rotate object relative to camera
- Rigidbody.addforce
- two players one phone unity gamne
- c# length of array
- asp textarea
- c# remove last value from list
- unity mouse click position
- array copy c#
- max of array C#
- .net core session