- Home /
Question by
Aedo98 · Jul 03, 2020 at 05:00 PM ·
script.drag objects
Drag object script suggestion
Hi, the script works fine but i want to drag object with right click and not the left, any suggestions?
public class MouseDrag : MonoBehaviour {
Vector3 dist;
float posx;
float posy;
void OnMouseDown()
{
dist = Camera.main.WorldToScreenPoint(transform.position);
posx = Input.mousePosition.x - dist.x;
posy = Input.mousePosition.y - dist.y;
}
void OnMouseDrag()
{
Vector3 curPos = new Vector3(Input.mousePosition.x - posx, Input.mousePosition.y - posy, dist.z);
Vector3 worldPos = Camera.main.ScreenToWorldPoint(curPos);
transform.position = worldPos;
}
}
Comment
Answer by Frame-Matt · Jul 10, 2020 at 08:19 PM
Hi there.
What about changing into a OnMouseOver(), and check if(Input.GetMouseButton(1)) { //stuff }
for that rightclick?
Or maybe youcould try this: https://answers.unity.com/questions/1653917/how-can-i-move-2d-object-with-dragging-right-mouse.html
Cheers!
Your answer
Follow this Question
Related Questions
Add to list/scroll view in script,Add ui object to listview in code 1 Answer
Platform move left and right randomly 1 Answer
NetcodeForGameObjects compilation error 1 Answer
Change animation exit time 1 Answer
Rigidbody Not Move 0 Answers