Ok, two seperate classes.
First of all, there’s my SelectionManager class, it governs selecting of units (isometric/topdown game) and i want it to fire off an event whenever the selection changes.
I’m using this to define the event:
public delegate void SelectionEventHandler(GameObject justSelected);
public event SelectionEventHandler SelectionChanged;
And i’m using this line to fire off an event
SelectionChanged(active);
This compiles without errors, but i’ve not been able to test it.
Secondly, the other class, this one is named FixedCamera
It contains a reference to the instance of my SelectionManager class (the reference variable is named “selectionManager”)
I’m attempting to define a listener on the aforementioned event, like this:
selectionManager.SelectionChanged += new SelectionEventHandler(SetSubject);
However this won’t compile, SelectionEventHandler has a red underline. The tooltip error is: “The type or namespace “SelectionEventHandler” could not be found…”
My obvious first thought then, is that it doesn’t know where to look, so i tried this
selectionManager.SelectionChanged += new selectionManager.SelectionEventHandler(SetSubject);
However this throws a different error
“selectionManager is a field, but is used like a type”
I’m stumped. What am i not getting?
That's fair enough. :) (downvote removed). Though, the typical approach to object selection is to have e.g. OnSelected events associated with the object instances rather than a global manager. Just like something like "OnMouseEnter" is associated with each instance of MonoBehaviour. But one could argue that concerns the pattern OP followed rather than his issue with calling syntax, so your answer is correct.
– CHPedersen