Hi all -
I’ve an event in one class and a listener in the other. The Sender class transmits an event with an integer value which the Receiver class will need to store and do something with. Is there a way to set the value of the variable in the listener to the value transmitted via the event without first creating a method to subscribe to the event?
For example, instead of:
public class Receiver : Monobehaviour {
int value;
void Start ()
{
SenderClass.Event += ChangeValue;
}
void ChangeValue(int amount);
{
value = amount;
}
}
I’d like something to the effect of:
public class Receiver : Monobehaviour {
int value;
void Start()
{
SenderClass.Event += value;
}
}
Essentially, is there a way around having to create a method to change the variable the value of which is arriving from the outside via an event? Creating such one-off methods feels a bit, well, redundant.