Search Unity

Help with delegates

Discussion in 'Scripting' started by Kovenant, Apr 21, 2015.

  1. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    I got this error and I can't see what's wrong with it.. I have abunch of other delegates which works just fine

    "TillHead.cs(22,33): error CS0019: Operator `+=' cannot be applied to operands of type `EventHandler.EO_SmallImpact' and `void'"

    EventHandler.cs:
    Code (CSharp):
    1. public delegate void EO_SmallImpact();
    2. public static EO_SmallImpact EO_OnSmallImpact;
    3.  
    4. public static void EO_OnSmallImpactEvent()
    5.     {
    6.         if (EO_OnSmallImpact != null)
    7.             EO_OnSmallImpact();
    8.     }
    Tillhead.cs:
    Code (CSharp):
    1. void OnEnable()
    2.     {
    3.         EventHandler.EO_OnSmallImpact += this.OnSmallImpact ();
    4.     }
    5.  
    6.     void OnDisable()
    7.     {
    8.         EventHandler.EO_OnSmallImpact -= this.OnSmallImpact ();
    9.     }
    Am I blind? :)
     
  2. psyydack

    psyydack

    Joined:
    Aug 30, 2013
    Posts:
    93
    I think you code complete is trolling you. Just remove referent to execute method :

    Tillhead.cs (become this)
    Code (CSharp):
    1. void OnEnable()
    2.     {
    3.         EventHandler.EO_OnSmallImpact += this.OnSmallImpact;
    4.     }
    5.     void OnDisable()
    6.     {
    7.         EventHandler.EO_OnSmallImpact -= this.OnSmallImpact;
    8.     }
     
    Kovenant likes this.
  3. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    omg.. I was blind :D Thank you! :)