- Home /
C# Enum for Animation Issue
I'm using an enum to track the animation currently playing in my character movement script. Whenever I try to use certain parts of the enumeraction, I get the following error:
Assets/SpartanController.cs(75,66): error CS0117:
CharacterState' does not contain a definition for
Attacking'
Line 75 is as follows:
_characterState = CharacterState.Attacking;
What's surprising about this error is that it works for similar statements (the first 3 enum elements). For example, the following line of code executes error-free:
_characterState = CharacterState.Running;
Here is my enum declaration:
enum CurrentAnimation
{
Idle = 0,
Walking = 1,
Running = 2,
Charging = 3,
IdleBattle = 4,
Resisting = 5,
Victory = 6,
Saluting = 7,
Dying = 8,
DyingHard = 9,
Attacking = 10
};
`private CharacterState _characterState;`
Answer by by0log1c · Dec 30, 2011 at 07:59 AM
Hmm, well the enum declaration you show us does contains the desired elements but its called CurrentAnimation. The variable use the CharacterState enum - which I figure holds the same working elements from CurrentAnimation but not the others.
Wow, I can't believe I didn't notice that... thanks! But I used the search feature to search for additional enums, and the CharacterAnimation enum is the only enum in the file (there is no CharacterState enum). I'm really confused about how the first three animations ran.
Anyways, it's working now, so I suppose it doesn't really matter. Thanks again!
The enum doesn't need to be in the same file. It can be defined in another file.
In most IDEs (I don't know if $$anonymous$$onoDevelop has this feature, but Visual Studio has it) you can right-click any identifier and click "go to definition". It will open the file which contains the element and scrolls to the definition.
That must have been it. I had the controller scripts that come from the Character Controller package to compare my script to (could have actually used those, but then I wouldn't have learned anything). One of the scripts in there had CharacterState defined.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Animation Error 0 Answers
Cannot Implicitly convert to bool problem? 1 Answer
help me please dont understand problem with animation 0 Answers