how to use Enum? C# I'm keep getting Unexpected symbol `enum'

ok I’m bugging my head with this a while

using System;
enum Layer{
	Protagonists = 9,
	Antagonists = 10,
	HeadsUpDisplay = 11,
	LevelBoundaries = 13
};

with or without semicolon just doesn’t work

saw many accepted answers tried them all nothing seem to work where am I looking wrong?

and I keep getting same error

Assets/Scripts/_Class/_Struct/SkillGain.cs(39,24): error CS1525: Unexpected symbol `enum'

from answers I kinda figure out that I don’t declare after enum (Layer) what type is it
in this case
so where do I tell it what is it float/int/GameObject?

I’ve tried many things:

  • enum float layer
  • enum layer float

both with and without semicolon on end

I’ve tried to empty the inside {}

and getting same error

EDIT:

and OFC if it’s a bug tell me I’m using unity 4.0.1

full code

using UnityEngine;
using System.Collections;


enum Layer {
	Protagonists = 9,
	Antagonists = 10,
	HeadsUpDisplay = 11,
	LevelBoundaries = 13
}


public struct SkillGain{
	public void GetExpF (float[] SkillExperienceList, int UpdateSkillExperienceNumber, float SkillGainf, char ToolLimb){
		Layer layer = Layer.Antagonists;
		int asdf = layer;
		// we increase skill
		SkillExperienceList[UpdateSkillExperienceNumber] += Mathf.Log(SkillGainf, SkillExperienceList[UpdateSkillExperienceNumber]);
		
		// we increase body strength depending on UpdateExperience number
		if (UpdateSkillExperienceNumber == 19){
			Woodcutting(SkillExperienceList, ToolLimb);
		}
	}
	private void Woodcutting (float[] SkillList, char ToolLimb){
		if (ToolLimb == 'L'){
			SkillList[2] = 10 ;
			SkillList[3] = 1.5f ;
			SkillList[4] = 7 ;
			SkillList[6] = 15 ;
			SkillList[8] = 10 ;
			SkillList[10] = 1.5f ;
			SkillList[12] = 5 ;
			SkillList[15] = 6 ;
		}
		else if (ToolLimb == 'R'){
			SkillList[2] = 10 ;
			SkillList[3] = 1.5f ;
			SkillList[4] = 7 ;
			SkillList[6] = 15 ;
			SkillList[8] = 10 ;
			SkillList[10] = 1.5f ;
			SkillList[12] = 5 ;
			SkillList[15] = 6 ;
		}
		else{Debug.Log("ERROR SkillGain has N limb instead of L/R");}
	}
	private void Attack0 (float[] SkillList, float Strength){//10Kg
		float shoulder = 0;
		float arm = 0;
		float forearm = 0;
		float wraist = 100;
		float tight = 0;
		float leg = 0;
		float back = 0;
		float sum = 0;
		float StartPer = 10;
		sum = shoulder + arm + forearm + wraist + tight + leg + back;
		
		wraist = (wraist/sum)*((Strength/100)*StartPer);
		
		SkillList[0] = 0 ;//"Body Strengths";
			SkillList[1] = 0 ;//"Neck Strength";
			SkillList[2] = 0 ;//"Back Strength";
			SkillList[3] = 0 ;//"Six Pack Strength";
			SkillList[4] = 0 ;//"Left Shoulder Strength";
 				SkillList[6] = 0 ;//"Left Arm Strength";
				SkillList[8] = 0 ;//"Left Forearm Strength";
				SkillList[10] = 0 ;//"Left Wraist Strength";
			SkillList[5] = 0 ;//"Right Shoulder Strength";
				SkillList[7] = 0 ;//"Right Arm Strength";
				SkillList[9] = 0 ;//"Right Forearm Strength";
				SkillList[11] = 0 ;//"Right Wraist Strength";
				
			SkillList[12] = 0 ;//"Left Tight Strength";
				SkillList[14] = 0 ;//"Left Leg Strength";
				SkillList[16] = 0 ;//"Left Foot Strength";
			SkillList[13] = 0 ;//"Right Tight Strength";
				SkillList[15] = 0 ;//"Right Leg Strength";
				SkillList[17] = 0 ;//"Right Foot Strength";
	}
	private void Attack1 (float[] SkillList, float Strength){
		float shoulder = 90;
		float arm = 100;
		float forearm = 0;
		float wraist = 0;
		float tight = 0;
		float leg = 0;
		float back = 0;
		float sum = 0;
		float StartPer = 60;
		sum = shoulder + arm + forearm + wraist + tight + leg + back;
		
		shoulder = (shoulder/sum)*((Strength/100)*StartPer);
		arm = (arm/sum)*((Strength/100)*StartPer);
		
		// calculation is correct
	}
	private void Attack2 (float[] SkillList){
		
	}
// Top,	Middle	Bottom
// 0,	2,		4 right ones
// 1,	3,		5 left ones
// 0 10 wraist 100															300	Wraist 100, forarm 90, arm 50
// 1 60 arm 100, shoulder 90												250 shoulder 100, arm 90, tight 10 (other leg 5)
// 
// back works here at both I'll test it again
// 2 100 arm 100, shoulder 90, forearm 35, wraist 20, tight 10, leg 5		400 arm 100, shoulder 70, tight 10, leg 5
// 3 100 shoulder 90, arm 70, tight 10										400	arm 100, shoulder 70, tight 20, leg 5
//
// 4 10 wraist 100, forearm 50												250	wraist 20
// 5 60 shoulder 90 arm 80													250	shoulder 70 arm 60 wraist 10
//
// thrust 
// 6 100 shoulder 100, arm 70, forearm 20, wraist 30, (other leg 10)		100 shoulder 80, arm 100, wraist 20, (other leg 10), (other tight 5) back 10
	private void Attack3 (float[] SkillList){
		SkillList[0] = 0 ;//"Body Strengths";
			SkillList[1] = 0 ;//"Neck Strength";
			SkillList[2] = 0 ;//"Back Strength";
			SkillList[3] = 0 ;//"Six Pack Strength";
			SkillList[4] = 0 ;//"Left Shoulder Strength";
 				SkillList[6] = 0 ;//"Left Arm Strength";
				SkillList[8] = 0 ;//"Left Forearm Strength";
				SkillList[10] = 0 ;//"Left Wraist Strength";
			SkillList[5] = 0 ;//"Right Shoulder Strength";
				SkillList[7] = 0 ;//"Right Arm Strength";
				SkillList[9] = 0 ;//"Right Forearm Strength";
				SkillList[11] = 0 ;//"Right Wraist Strength";
				
			SkillList[12] = 0 ;//"Left Tight Strength";
				SkillList[14] = 0 ;//"Left Leg Strength";
				SkillList[16] = 0 ;//"Left Foot Strength";
			SkillList[13] = 0 ;//"Right Tight Strength";
				SkillList[15] = 0 ;//"Right Leg Strength";
				SkillList[17] = 0 ;//"Right Foot Strength";
	}
	private void Attack4 (float[] SkillList){
		
	}
	private void Attack5 (float[] SkillList){
		
	}
	private void Attack6thrust (float[] SkillList){
		
	}
}

Your problem is that you are trying to declare the enum in a function scope.

In C#, enums are their own types, just like classes. So you can only declare them in the global scope or within a class scope, like this:

// GOOD
enum Enum1
{
    //...
};

class Class1
{
    // GOOD
    enum Enum2
    {
        //...
    };

    void Function1()
    {
        // BAD
        enum Enum3
        {
            //...
        };
    }
}

Where are you declaring the enum?

Edit: After seeing your code, the problem is definitely that you’re declaring the enum in the wrong place. They cannot be declared inside of a method.

Here’s an example:

enum Layer { Protagonists = 9, Antagonists = 10, HeadsUpDisplay = 11, LevelBoundaries = 13 }

class TestClass
{
  Layer layer = Layer.Antagonists;
}

The enum cannot be declared inside of a method. It’s either at the class level or higher. Also, no special namespace (e.g. System) is required.