- Home /
 
"The event can only appear on the left hand side of `+=' or `-=' operator"
Hey, iam trying to sync some values to an action event by doing this:
 public event System.Action<Vector3> OnTriggerBail
         {
             [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
             add
             {
                 this.OnTriggerBail = (System.Action<Vector3>)System.Delegate.Combine(this.OnTriggerBail, value);
             }
             [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
             remove
             {
                 this.OnTriggerBail = (System.Action<Vector3>)System.Delegate.Remove(this.OnTriggerBail, value);
             }
         }
 
         public event Action OnTriggerLanding
         {
             [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
             add
             {
                 this.OnTriggerLanding = (Action)System.Delegate.Combine(this.OnTriggerLanding, value);
             }
             [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
             remove
             {
                 this.OnTriggerLanding = (Action)System.Delegate.Remove(this.OnTriggerLanding, value);
             }
         }
 
               but iam getting the error: The event OnTriggerBail' can only appear on the left hand side of +=' or `-=' operator
any idea why?
               Comment
              
 
               
              Answer by Hellium · Jul 05, 2017 at 09:03 AM
You are declaring an accessor for the OnTriggerBail event, but you use it inside the add and remove. You have to create a private event onTriggerBail you will be able to use inside your accessors (the same apply for your other event)
      private event System.Action<Vector3> onTriggerBail;
      public event System.Action<Vector3> OnTriggerBail
      {
          [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
          add
          {
              onTriggerBail = (System.Action<Vector3>)System.Delegate.Combine(onTriggerBail, value);
          }
          [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
          remove
          {
              onTriggerBail = (System.Action<Vector3>)System.Delegate.Remove(onTriggerBail, value);
          }
      }
 
              Your answer
 
             Follow this Question
Related Questions
is there any easier way to do this ? 2 Answers
A node in a childnode? 1 Answer
When to use 'delegate', 'event' or 'Action' ? 1 Answer
How to make a list of Actions or methods? 1 Answer
Clear event System.Action list 1 Answer