有限状态机的问题“错误CS1503:参数1:无法从'UIManager'转换为'GameStateAbstract'”]]

问题描述 投票:0回答:1

我是Unity新手。我已经在学习的同时开始开发基本游戏,但是在尝试链接状态时会出现以下错误(用于菜单系统)。

错误似乎是相同的:

参数1:无法从'UIManager'转换为'GameStateAbstract']

参数1:无法从'UIManager'转换为'GameStateAbstract'//在另一行中附加相同的文件

参数1:无法从'GameManager'转换为'GameStateAbstract']

context(UIManager):

public class UIManager : MonoBehaviour 
{
#UIManager Singletons
private static UIManager _instance;
public static UIManager Instance
{
    get
    {
        if (_instance == null)
        {
            Debug.LogError("UIManager is NULL");
        }
        return _instance;
    }
}

#Fields
public GameObject gameOverPanel;
public GameObject onPlayOverlays;
public GameObject startMenuPanel;

public GameStateAbstract _currentState;

public readonly PlayStates onPlayStates = new PlayStates();
public readonly DeadStates onDeadStates = new DeadStates();
public readonly MenuStates onMenuStates= new MenuStates();

public void TransitionToState(GameStateAbstract state)
{
    _currentState = state;
    _currentState.EnterState(this);
}
public void Context(GameStateAbstract state)
{
    _currentState.Conditions(this);
}
void Awake()
{
    _instance = this;
    TransitionToState(onMenuStates);
}
}

抽象状态:

public abstract class GameStateAbstract 
{
public abstract void EnterState(GameStateAbstract layer); 

public abstract void Update(GameStateAbstract layer);

public abstract void Conditions(GameStateAbstract layer);
}

具体状态:

public class MenuStates : GameStateAbstract 
{

public override void Update(GameStateAbstract layer)
{
}
public override void EnterState(GameStateAbstract layer)
{
}
public override void Conditions(GameStateAbstract layer)
{
}
}

GameManager:

public class GameManager : MonoBehaviour
{
void Update()
{
UIManager.Instance.CurrentState.Update(this);
}
}

感谢您的回答!

我是Unity新手。我已经在学习的同时开始开发基本游戏,但是在尝试链接状态时会出现以下错误(用于菜单系统)。错误似乎是相同的:...

c# unity3d state-machine game-development
1个回答
0
投票
public abstract void Update(GameStateAbstract layer);
© www.soinside.com 2019 - 2024. All rights reserved.