While poking around learning c# I stumbled upon this code, it’s from working example so obviously code worked and now unity throws error The event ‘Test.OnMove’ can only appear on the left hand side of += or -=.
I’m a newbie, can somebody help and explain how this worked without private event “private event Action _onMove” because I found that people recomend that for this error.
public class Test : MonoBehaviour
{
public event Action<Test> OnMove
{
add
{
Action<Test> action = this.OnMove;
Action<Test> action2;
do
{
action2 = action;
action = Interlocked.CompareExchange(ref this.OnMove, (Action<Test>)Delegate.Combine(action2, value), action);
}
while (action != action2);
}
remove
{
Action<Test> action = this.OnMove;
Action<Test> action2;
do
{
action2 = action;
action = Interlocked.CompareExchange(ref this.OnMove, (Action<Test>)Delegate.Remove(action2, value), action);
}
while (action != action2);
}
}
}