Search Unity

Enum.GetName() method ?

Discussion in 'Scripting' started by DeepStarSix, Apr 1, 2015.

  1. DeepStarSix

    DeepStarSix

    Joined:
    Apr 1, 2015
    Posts:
    2
    public class Enemy: MonoBehaviour {
    public enum Spells: int { Fireball, Lightning, ForcePush }

    void CastSpell(Spells spell)
    {

    // in regular C# this is possible
    print(String.Format("{0} spell casted", Enum.GetName(typeof(Spells), spell)));
    }

    }

    How can I do something like this C# unity script?
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Should work.
    System.Enum.GetName(..)
     
    ow3n and DeepStarSix like this.
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    I suspect you copied an example that had "using System" and forgot to include that bit at the top of your file.

    Although in this case, you could presumably just use "spell.toString()" instead...
     
    Abdulrazek likes this.
  4. DeepStarSix

    DeepStarSix

    Joined:
    Apr 1, 2015
    Posts:
    2
    Cool. Thank you.
    VStudio imports by default the System namespace. MonoDevelop doesn't by default.
    Its a good lesson for me.