how to right click OnMouseDrag C#

I want with right mouse button to drag how would I do that?

void OnMouseDrag (){
	if (Input.GetMouseButtonDown(1)){Debug.Log("asdeglkzug");}
}

I know it only allows me with left button but why and how do I fix it?

You could write a script that can handle dragging for all mouse buttons, but I’m in a good mood and I wrote a basic one. The basic idea is checking if a button is down, and if it is down, check if it was down in the previous frame too. If yes, then we are dragging. During these checks, you can add your own mechanism for example if you want a drag to happen on a collider or gui element, these are all checks you can even implement if you temper directly with this class or even better, subclass this and write further checks in the callbacks.

To make it easier to extend, I separated the drag callbacks to start drag, dragging, end drag, so one can flexibly extend this script with subclassing, since the basic fact that the user is dragging with a mouse button is independent of any further logic.

This has another neat feature, that is you can drag with multiple buttons at once, callbacks will be called for each mouse button. The script:

public class MouseDrag : MonoBehaviour {

	// array for storing if the 3 mouse buttons are dragging
	bool[] isDragActive;

	// for remembering if a button was down in previous frame
	bool[] downInPreviousFrame;

	void Start () {
		isDragActive = new bool[] {false, false, false};
		downInPreviousFrame = new bool[] {false, false, false};
	}
	
	void Update () {
		for (int i=0; i<isDragActive.Length; i++)
		{
			if (Input.GetMouseButton(i))
			{
				if (downInPreviousFrame*)*
  •  		{*
    

_ if (isDragActive*)_
_
{_
_
OnDragging(i);_
_
}_
_
else*_
* {*
_ isDragActive = true;
* OnDraggingStart(i);
}
}
downInPreviousFrame = true;
}
else*

* {
if (isDragActive)
{
isDragActive = false;
OnDraggingEnd(i);
}
downInPreviousFrame = false;
}
}
}*_

* public virtual void OnDraggingStart(int mouseButton)*
* {*
* // implement this for start of dragging*
* Debug.Log(“MouseButton” + mouseButton + " START Drag");*
* }*

* public virtual void OnDragging(int mouseButton)*
* {*
* // implement this for dragging*
* Debug.Log(“MouseButton” + mouseButton + “DRAGGING”);*
* }*

* public virtual void OnDraggingEnd(int mouseButton)*
* {*
* // implement this for end of dragging*
* Debug.Log(“MouseButton” + mouseButton + " END Drag");*
* }*
}

I think you have to write the function yourself. As far as I know those functions only work with left click. To simulate you would have to detect the right click in Update, see if there is a collision with the mouse and object you are targeting then see if the mouse has moved.