I’m writing a script to make a variable in my script lerp on a button press. Here’s my script…
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 keep getting this error even though ‘MonoBehaviour’ is clearly stated at the beginning…
Assets/SwithShoulders.cs(1,28): error CS0246: The type or namespace name `MonoBehaviour’ could not be found. Are you missing a using directive or an assembly reference?