3

I have been coding with C# and have run into some issues. I have been following this YouTube tutorial and I have some errors. On line seven in Walking state code it says:

Error CS0507 'WalkingState.ProcessMotion(Vector3)': cannot change access modifiers when overriding 'public' inherited member 'BaseState.ProcessMotion(Vector3)'

What does this mean and how can I fix this?

Base state code:

using UnityEngine;
using System.Collections;

public abstract class BaseState : MonoBehaviour
{
    protected BaseMotor motor;

    #region baseState implementation
    public virtual void Construct()
    {
        motor = GetComponent<BaseMotor>();
    }
    public virtual void Destruct ()
    {
        Destroy(this);
    }
    public virtual void Transition ()
    {

    }
    #endregion

    public abstract Vector3 ProcessMotion(Vector3 input);
    public virtual Quaternion ProcessRotation(Vector3 input)
    {
        return transform.rotation;
    }
}

Walking state code:

using UnityEngine;
using System.Collections;

public class WalkingState : BaseState
{
    protected override Vector3 ProcessMotion(Vector3 input)
    {
        return input * motor.Speed;
    }
}
user3071284
  • 6,955
  • 6
  • 43
  • 57
JakeW
  • 103
  • 1
  • 1
  • 4

2 Answers2

9

ProcessMotion is declared public in the base class. You need to also make it public in the derived class.

Instead of:

protected override Vector3 ProcessMotion(Vector3 input)

do:

public override Vector3 ProcessMotion(Vector3 input)
E. Moffat
  • 3,165
  • 1
  • 21
  • 34
3

The error message is quite clear: the base class has the method marked as public but you're trying to change it into protected in the deriving class. This is not permitted, it must also be public in the deriving class.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74