- Home /
Question by
sloopernine · Jul 03, 2013 at 11:25 PM ·
c#animationenumcompare
Enums compare question C#
Hi, I get error when trying to compare my enum with its old value.
error CS0019: Operator !=' cannot be applied to operands of type
GamePlayerAnimation.AnimState' and `int'
I thought the enums was some kind of fancy int´s ?
using UnityEngine;
using System.Collections;
using TNet;
public class GamePlayerAnimation : TNBehaviour {
// Most common animation states.
public enum AnimState
{
Idle,
Walk,
Run,
WalkBack,
jump
}
public AnimState currentAnimState;
public int _oldAnimationState;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (tno.isMine)
{
if (currentAnimState != _oldAnimationState)
{
tno.Send("AnimState", TNet.Target.OthersSaved, currentAnimState);
_oldAnimationState = currentAnimState;
}
}
Comment
Answer by iwaldrop · Jul 03, 2013 at 11:31 PM
You can cast the int value of the enum.
if ((int)currentAnimState != _oldAnimationState)
Or, better yet, store _oldAnimationState as the enum value:
AnimState _oldAnimationState;
Your answer
Follow this Question
Related Questions
C# Enum for Animation Issue 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Using C# Enums to Control an Animator 2 Answers
enum not referencing properly 1 Answer