How do I use lerping?

I’ve been trying to figure out lerping (I’m also switching from JavaScript to CSharp so I’m not great at it yet either), so I can lerp a variable called ‘xOffset’ in a script titled ‘MouseOrbitOTS’ from 0.75 to -0.75 when the input ‘Switch Shoulders’ is tapped. Here’s what I managed to write on my own by editing a code I found online, but I still get some errors…

using UnityEngine;
public class LerpExample : MonoBehaviour {
    float lerpTime = 1f;
    float currentLerpTime;
   
    float moveDistance = 10f;
   
    Vector3 startPos;
    Vector3 endPos;
   
    protected void Start() {
        startPos = MouseOrbitOTS.xOffset;
        endPos = MouseOrbitOTS.xOffset + transform.up * moveDistance;
    }
   
    protected void Update() {
        //reset when we press spacebar
        if (Input.GetButtonDown("Switch Shoulders")) {
            currentLerpTime = 0f;
        }
       
        //increment timer once per frame
        currentLerpTime += Time.deltaTime;
        if (currentLerpTime > lerpTime) {
            currentLerpTime = lerpTime;
        }
       
        //lerp!
        float perc = currentLerpTime / lerpTime;
        MouseOrbitOTS.xOffset = Vector3.Lerp(startPos, endPos, perc);
    }
}

But I get these errors…

Assets/SwithShoulders.cs(12,42): error CS0120: An object reference is required to access non-static member MouseOrbitOTS.xOffset' Assets/SwithShoulders.cs(12,42): error CS0120: An object reference is required to access non-static member MouseOrbitOTS.xOffset’
Assets/SwithShoulders.cs(30,31): error CS0120: An object reference is required to access non-static member `MouseOrbitOTS.xOffset

Could someone please fix the code or at least tell me what I can do to fix it? Thanks!

Reference an instance of the class MouseOrbitOTS or make the variable xOffset inside that class static

I’m sorry, but I’m not sure how to do that. When said I was switching from JavaScript to CSharp, I meant I started teaching myself about 2 days ago. Could you show some sort of example on how to make the xOffset static?

if you want a class with some global values inside of there (which you cannot access from the unity editor without some more work), you can make it static:

public static class MouseOrbitOTS
{
    public static float xOffset = 0.75f;

   // or as constant:
    public const float X_OFFSET = 0.75f;

}