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!