遇到麻烦了。找不到我搞砸的地方。如果有人能发现这个问题,我会非常感激的。错误是: error CS1031: Type,我尝试在脚本上运行Unity,但没有成功。我真的不觉得有什么问题。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AiStateMachine :
{
public AiState[] states;
public AiAgent agent;
public AiStateId currentState;
public AiStateMachine(AiAgent agent)
{
this.agent = agent;
int numStates = System.Enum.Getnames(typeof(AiStateId)).Length;
states = new AiState[numStates];
}
public void RegisterState(AiState state)
{
int index = (int)state.GetId();
states[index] = state;
}
public AIStateMachine GetState(AiStateId stateId)
{
int index = (int)stateId;
return states[index];
}
public void Update()
{
GetState(currentState)?.Update(agent);
}
public void ChangeState(AiStateId newState)
{
GetState(currentState)?.Exit(agent);
currentState = newState;
GetState(currentState)?.Enter(agent);
}
}发布于 2021-12-19 13:40:10
类名后面有一个悬空冒号(:)。由于您没有继承任何类,所以不应该有冒号:
public class AiStateMachine
{
// ":" removed here ----^发布于 2021-12-19 13:46:34
虽然在这个特殊情况下,这并不一定有帮助,但我想提到的是,如果您搜索错误代码,通常会有来自微软的一些信息来帮助一些人。下面是这个错误的一个:
https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs1031
不过,在本例中,似乎有一个类希望通过类声明末尾的冒号来派生,而后面没有任何信息:
public class AiStateMachine : 尝试删除冒号或添加类应该继承的内容。如果需要的话,这个页面还有一些很好的信息可以浏览继承:
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/tutorials/inheritance
https://stackoverflow.com/questions/70411918
复制相似问题