error CS0120: An object reference is required to access non-static member `CameraOperator.InvertMouseY(float)

I am making a RTS style game and I have an error
error CS0120: An object reference is required to access non-static member `CameraOperator.InvertMouseY(float)

Here is the script text with error.

camPos.y = CameraOperator.InvertMouseY (camPos.y);

Any help would be great.

The “InvertMouseY( float val )” is a non static function of the class “CameraOperator”. In order to access it, you can have two ways:

  1. The first is defining the object of CameraOperator class and call the InvertMouseY function. However, make sure that you pass the reference or initialize the object first otherwise you will encounter “Null Reference Exception”.

    CameraOperator mCam;

    void Start()
    {
    mCam =
    }

    void foo()
    {
    camPos.y = mCam.InvertMouseY (camPos.y);
    }

  2. You can make the InvertMouse function static, however, you must not access any non static member of CameraOperator class in that function. Then this line will work:

    camPos.y = CameraOperator.InvertMouseY (camPos.y);