【发布时间】:2018-10-21 03:29:57
【问题描述】:
我有以下基类
public abstract class Character : MonoBehaviour
{
protected abstract Enum CurrentState
{
get;
set;
}
}
和下面的子类
public class Player : Character
{
protected override Enum CurrentState
{
get
{
return (State)_anim.GetInteger("State");
}
set
{
_anim.SetInteger("State", Convert.ToInt32(value));
}
}
private enum State
{
IDLE = 0,
WALK = 1,
JUMP = 2,
FALL = 3,
CLIMB = 4,
LOOKING_DOWN = 5,
NPC = 6,
IMPATIENT = 7,
LOOKING_UP = 8,
STUCK = 9,
}
void FixedUpdate()
{
if (CurrentState == State.CLIMB)
{
}
}
}
线
if (CurrentState == State.CLIMB)
产生以下错误:运算符“==”不能应用于“Enum”和“Player.State”类型的操作数
有什么帮助吗?吸气剂工作正常。那么也许我需要在 set 访问器中进行强制转换?我不太确定...我对此有点陌生...任何帮助将不胜感激。
【问题讨论】:
-
尝试将私有枚举更改为您的类对象之外的公共枚举
-
什么让你困惑?
CurrentState是Enum类型,State.Climb是State类型 -
枚举 catch22 的简明答案位于此处:stackoverflow.com/questions/22335103/…
-
你可以在这里查看如何比较枚举:stackoverflow.com/questions/19537083/…
-
我认为您需要一个 CurrentState 属性来设置/获取 State 类型的值。 CurrentState 不应该是枚举。
标签: c# unity3d enums enumeration