c# - 更改访问修饰符

标签 c# unity3d

<分区>

我一直在使用 C# 进行编码,但遇到了一些问题。我一直在关注this YouTube tutorial我有一些错误。在 Walking 状态代码的第七行,它说:

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

这是什么意思,我该如何解决?

基本状态代码:

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;
    }
}

行走状态代码:

using UnityEngine;
using System.Collections;

public class WalkingState : BaseState
{
    protected override Vector3 ProcessMotion(Vector3 input)
    {
        return input * motor.Speed;
    }
}

最佳答案

ProcessMotion 在基类中声明为 public。您还需要在派生类中将其设为 public

代替:

protected override Vector3 ProcessMotion(Vector3 input)

做:

public override Vector3 ProcessMotion(Vector3 input)

关于c# - 更改访问修饰符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33656807/

相关文章:

c# - BackgroundWorker 异常处理

c# - 在着色器中使用来自 c# 脚本的函数

xcode-无法获得对握手数据包的答复

c# - Windows Azure WorkerRole 无法从类库中加载文件 xxx.XmlSerializers

c# - Sitecore:在类型为 ="DateTime"的 sitecore 字段中保存日期 <Input type ="text">

c# - TestCafe 是否与 C# .Net 集成?

c# - 使用 JSON 发布请求,但服务器端有 Request.Form.Count == 0

c# - 如何更有效地将字典数据或arraylist数据保存到playerprefs?

c# - 有没有更好的移动方式?

c# - 有没有更有效的方法来禁用多个脚本,同时在 Unity 中的单个游戏对象上保持一些事件?