How to adjust xMotion on configurable joint via c# script?

The title is basically the entire question. I need to set xMotion on a configurable joint to “limited” and I can’t find a way to do it outside of doing it manually in the editor, which won’t work since my joint is spawned during runtime. I would really appreciate any help.

How to adjust xMotion on configurable joint via c# script?

//Create joint
ConfigurableJoint configJoint = gameObject.AddComponent(typeof(ConfigurableJoint)) as ConfigurableJoint;
//Set xmotion to locked
configJoint.xMotion = ConfigurableJointMotion.Limited;

@birdbrain5
Here’s an example script:

//This script would be attached to the GameObject of the Configurable Joint
using UnityEngine;
using System.Collections; 

public class adjustXMotion : MonoBehavior {
    //Set a variable for the joint
    private ConfigurableJoint joint;

    void Start(){ //Block of code to execute when initiating the level:
         /* Set the joint var to be the Configurable Joint component attached to the GameObject 
         this script is attached to */

         joint = gameObject.GetComponent<ConfigurableJoint>();
    }

    void Update(){ //Call this block every frame:
        //Lock the xMotion
        joint.xMotion = ConfigurableJoint.Locked;
    }
}

You can change [...]Locked; to Free or Limited

If you have any other questions, please let me know!