Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[SOLVED] Why am I not able to cast this enum to an int?

Discussion in 'Scripting' started by Deleted User, Dec 21, 2014.

  1. Deleted User

    Deleted User

    Guest

    I have this Enum outside class / namespace declaration:

    Code (CSharp):
    1. public enum Element
    2. {
    3.         None = 0,
    4.         Fire = 1,
    5.         Ice = 2,
    6.         Earth = 3,
    7.         Dark = 4,
    8.         Light = 5
    9. }
    Then I have an interface which makes use of that enum:

    Code (CSharp):
    1. public interface IStats
    2. {      
    3.         float health { get; set; }
    4.         float damage { get; set; }
    5.         Element element { get; set; }
    6.  
    7.         void Damage (float damage, int source);
    8.    
    9. }
    Then I have a projectile class that implements interface IStats:

    Code (CSharp):
    1. public Element element { get; set ; }
    Code (CSharp):
    1.                 public void Damage (float sourceDamage, int source)
    2.                 {
    3.                         damage -= sourceDamage * Globals.elementDamage [(int)source.element, (int)element];
    4. }
    The problem is the line above. It tells me "int does not contain a definition for element".
     
  2. Random_Civilian

    Random_Civilian

    Joined:
    Nov 5, 2014
    Posts:
    55
    You have source as an int value...
    Perhaps you meant to pass a class or a struct
     
    Deleted User likes this.
  3. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Look at your argument "source" in Damage, its an int.

    Your trying to get member element of integer source, and then trying to cast the result of that to an int.
     
    Deleted User likes this.
  4. Deleted User

    Deleted User

    Guest

    Thanks guys... I spent 20 minutes on this and missed that...