Modifying wheel joint 2D motor speed

How to modify wheel joint 2d motor speed via script? when i try:

public class CarMovement : MonoBehaviour {

	public WheelJoint2D wheel;
	private float speed = 0f;

	void Start () {
		wheel.useMotor = false;
	}
	
	// Update is called once per frame
	void Update () {
				if (Input.GetKey(KeyCode.RightArrow)) {
						wheel.useMotor = true;
				}
				else if (Input.GetKey (KeyCode.LeftArrow)) {
						wheel.useMotor = true;
				} else {
						Debug.Log (speed);
						wheel.useMotor = false;
						wheel.motor.motorSpeed = speed;
						
						
				}

	}
}

They say: Cannot modify a value type return value of `UnityEngine.WheelJoint2D.motor’. Consider storing the value in a temporary variable

Googled and searched, can’t find answer anywhere.

Hi you need to use a JointMotor2d and asign the speed to it. After that asign this JointMotor2D to the WheelJoint2D’ motor.
The below code should set the speed to 50 on pressing the space key, I have not tested it, but it should work though.

public class CarMovement : MonoBehaviour 
{ 
	public WheelJoint2D wheel; 
	private float speed = 50f; 
	JointMotor2D jointMotor; 

	// Update is called once per frame 
	void Update () {
		if(Input.GetKey(KeyCode.Space)) {
			jointMotor.motorSpeed = speed; 
			wheel.motor = jointMotor;
			Debug.Log (speed); 
		} 
	} 
}

Make sure to check the useMotor chckbox. Also, make sure you have attached the wheelJoint2D to the car body with wheels as the child objects of the car body. Drag and drop this wheel into the Connected Rigidbody of the Wheeljoint2D atached to the car body.