How to make Rotation of HingeJoint2D constant via mouse button C#

cant seem to complete a script that can initiate the constant rotation of a hinge joint for as long as the mouse button is pressed, and then free spin on the joint after depressing.

using UnityEngine;
using System.Collections;

public class junk_wheeloffourtune : MonoBehaviour {
		

	public float velocity=1000;
	public float force=20;

	private HingeJoint joint;
	private JointMotor motor1;
	private bool buttonisdown=false;

	void Start()
	{
		joint = GetComponent<HingeJoint>(); // Get hingejoint
		joint.useMotor = false;
		motor1.force = force;
		motor1.targetVelocity = velocity;

		joint.motor = motor1;
	}


	void Update ()
	{


		if(Input.GetMouseButtonDown(0))
		{
			buttonisdown=true;
		}
		if(Input.GetMouseButtonUp(0))
		{
			buttonisdown=false;
		}


		if(buttonisdown)
		{
			joint.useMotor = true;
		}
		else
		{
			joint.useMotor = false;
		}
	}
}

okay probably not the best answer but it worked when i tried it.

i made
a plane. added rigidbody, no gravity
a Cylinder, added rigidbody, no gravity, angular drag 0.25 (pick one that feels right), a hingejoint on the Cylinder and connected it to the plane. picked y for my anchor and axis (not to sure which one was the right one so i changed them both)

force is how much force to put on the spin.
velocity is what is the max velocity expected on the motor.

then i check if mouse down or if mouse up. if down turn on motor. if mouse up turn off motor.

Good Luck :slight_smile: