passing string from broadcast messenger event to other function
Hello,
I am using Advanced CSharp Messenger (http://wiki.unity3d.com/index.php?title=Advanced_CSharp_Messenger) for my event system. It works pretty good so far but I want to seperate the script that has the event listeners and the scripts that actually change game elements. So I put listeners with the event functions in my interface script like this (please note that GameEvent.POSITION_UPDATED is just a string):
void Awake() {
Debug.Log ("Creating listeners...");
Messenger.AddListener<Vector3>(GameEvent.POSITION_UPDATED, EventPositionUpdated);
}
void OnDestroy() {
Messenger.RemoveListener<Vector3>(GameEvent.POSITION_UPDATED, EventPositionUpdated);
}
private void EventPositionUpdated(Vector3 data) {
otherClass.ChangeStuff ([here i want to pass along event string], data);
}
So now my question; what is the best way to pass along GameEvent.POSITION_UPDATED to the OtherClass.ChangeStuff function? I tried adding a string parameter to EventPositionUpdated() so it would become EventPositionUpdated(string event, Vector3 data) but apperently Advanced CSharp Messenger doesn't recognize that or I am epic failing somewhere.
ps: I want to compare the event string in the ChangeStuff function so that function knows what to do with the passed along data.
Thanks for taking the time.
Your answer
![](https://koobas.hobune.stream/wayback/20220612092041im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to set/reset a parameter at the end of animation? 3 Answers
How can I pass a reference to an Instantiated object? 0 Answers
Animation Controller Parameter Comparing 0 Answers
How to change variables that were the origins for parameters of a function with parameters. 1 Answer
root motion problem. direction parameter set to 90 on start 0 Answers