Is it possible to have events accept return values from methods as an parameter rather than having to “hardcode” a string for example?
I could pass a script so the method the event calls gets the desired value itself.
But that’s not very practical
I would like to pass a variable or a method with a return type.
Making it a bit more dynamic without having to write scripts to have this behaviour
I would try to extending the event system or something like that if that’s possible. But maybe i was just missing something
public class RandomStringGenerator : MonoBehaviour {
public string GetRandom() {
return // string with random characters;
}
}
When i click on a button i want to change the text of a Text Component to the value “GetRandom” returns.
Right now i would have to create a new script which is attached to that button:
public class ChangeText : MonoBehaviour, IPointerClickHandler {
public RandomStringGenerator rsg;
public Text label;
public void OnPointerClick(PointerEventData eventData) {
label.text = rsg.GetRandom();
}
}
That way i get the desired funcionality, but it’s strange that i have to create a script just to assign a value that could change.
It would be great to be able to set something like this up right in the button component.
i know this kind of stuff from c++ since your return value is a normal type it should be possible to take this return value and give it as agument to another function like
I understand your use case, but it’s not something that is easy to support or expose. Take for example you have a hook up with multiple targets that all return something, which one of the targets sets the value on the text?