- Home /
ugui, onclick, acceptable function signatures
Hello
What kinds of functions are acceptable for ugui onClick event? So far I noticed that return type must be void and function can have either no parameter or a single primitive parameter string, boolean,...
Do you guys know any definitive rules that would give me the big picture?
Can I use enum as parameter for instance?
Thank you.
Answer by OrbitGames · Sep 09, 2014 at 05:37 PM
They say it in the youtube tutorial at 10:30
It must be a public void. it can have 0 or 1 parameter, which can be of the type float, int, string, bool or unity object.
Answer by BrainWashG · Sep 09, 2014 at 05:59 PM
Pass it through an int and cast it as an enum when you get it back, you can also give an "Object" Parameter which give you most of the others parameters like GameObject transform and every single object inherited from it
PS : sorry for my english
This is not cool, because it enables a lot of errors during program$$anonymous$$g. I would also have to remember all the enum types and their order.
well lot of errrors? not really and you don't have to remember the enum types, its written on your code... tho there is no other solution to give an enum parameter, maybe i believe you can use a unity object
I appreciate your effort, but this is nothing short of a bad solution. And after all, its not enum anyway, I might as well use different function which would hold target component as a parameter with common interface or something else...
Yes I don't need to memorize the enum, but I would have to go search for it in the code. This would also move error detection from compile time to run time. It is just bad to deprive yourself of all the candy that .NET and unity editor are offering you. Unless its a micro project, you are going to have a bad time.
@BrainWashG's solution is perfectly valid and the way to go if an OnClick event needs to set an enum! ask for int or string as a parameter and cast it to the enum.
"Nothing short of a bad solution..." is really misplaced here because you never even gave a problem to start with, you just asked if enum's could be used as overload for an OnClicklistener, so: no not directly but yes if you follow BrainWashG's method.
Your answer