- Home /
Question by
$$anonymous$$ · Nov 10, 2014 at 08:55 PM ·
c#getcomponentclassenum
Accessing Enumeration from another script issue
Hello! Im trying to read enum type from another script but im getting this error
Type `Mob.Defence' does not contain a definition for `defenceType' and no extension method `defenceType' of type `Mob.Defence' could be found (are you missing a using directive or an assembly reference?)
First Script.
using UnityEngine;
using System.Collections;
public class Mob : MonoBehaviour {
[System.Serializable]
public class Defence
{
public float DefenceCount;
public DefenceType defenceType;
public enum DefenceType
{
Armor,
EnergyShield,
}
}
public Defence defence;
}
Second Script.
using UnityEngine;
using System.Collections;
public class Weapon : MonoBehaviour {
// Update is called once per frame
void Update ()
{
switch(target.gameObject.GetComponent<Mob>().defence.defenceType)
{
case Mob.Defence.DefenceType.Armor:
Debug.Log("Mob DefenceType is Armor");
break;
}
}
}
Comment
Worth noting that you can declare enums at the namespace level (ie outside of a class). Not sure if this makes sense for your project.
Best Answer
Answer by Bunny83 · Nov 10, 2014 at 09:21 PM
Looks fine to me. I guess you either haven't saved your last change or Unity didn't saw that change / update of the script. Make sure it's saved and try right-click -> reimport on the script in Unity.