Mathf Lerp?

I’m trying to work on a script for switching shoulders using Mathf lerping. Here’s what I’ve done so far…

var left : int = -0.75; //determines amount of zoom capable. Larger number means further zoomed in
var right : int = 0.75; //determines the default view of the camera when not zoomed in
var smooth : float = 5; //smooth determines speed of transition between zoomed in and default state
private var zoomedIn = false; //boolean that determines whether we are in zoomed in state or not
function Update () {
if(Input.GetButtonDown("Switch Shoulders")){        //This function toggles zoom capabilities with the Z key. If it's zoomed in, it will zoom out
zoomedIn = !zoomedIn;
}
if(zoomedIn == true){    //If "zoomedIn" is true, then it will not zoom in, but if it's false (not zoomed in) then it will zoom in.
MouseOrbitOTS.xOffset = Mathf.Lerp(MouseOrbitOTS.xOffset,left,Time.deltaTime*smooth);
}
else{
MouseOrbitOTS.xOffset = Mathf.Lerp(MouseOrbitOTS.xOffset,right,Time.deltaTime*smooth);
    }
}

My problem is, I get these errors that I don’t know how to fix…

Assets/SwitchShoulders1.js(14,15): BCE0020: An instance of type ‘MouseOrbitOTS’ is required to access non static member ‘xOffset’.
Assets/SwitchShoulders1.js(14,50): BCE0020: An instance of type ‘MouseOrbitOTS’ is required to access non static member ‘xOffset’.
Assets/SwitchShoulders1.js(18,15): BCE0020: An instance of type ‘MouseOrbitOTS’ is required to access non static member ‘xOffset’.
Assets/SwitchShoulders1.js(18,50): BCE0020: An instance of type ‘MouseOrbitOTS’ is required to access non static member ‘xOffset’.

I know it involves making a static variable, but I’m not sure how to do that. Could someone just add the variable to the code. Thanks!

It likely doesn’t involve making a static variable, it likely involves having an actual object instantiated so that you can utilize the instance variables. I have no idea what MouseOrbitOTS is, but if it’s a component on the same GameObject, then just use GetComponent() to grab that instance, and then call offsetX/Y on that instead.

Don’t make static variables, use GetComponent.

–Eric

Quite the opposite. You should read the error message more carefully. You are trying to access the xOffset member in the MouseOrbitOTS type, which is not a static member. So to access it, you need an actual instance of that class. But in your case, you are accessing it via the class directly, as a static member, which just doesn’t work.

Also, the error doesn’t really have anything to do with Mathf.Lerp() - the thread’s title is a bit misleading.