Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Lovrenc · Sep 09, 2014 at 10:06 AM · uionclickevent handlers

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lovrenc · Sep 09, 2014 at 06:04 PM 0
Share

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.

avatar image BrainWashG · Sep 09, 2014 at 10:18 PM 1
Share

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

avatar image Lovrenc · Sep 09, 2014 at 11:07 PM 0
Share

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.

avatar image jister Lovrenc · Apr 06, 2016 at 02:37 PM 0
Share

@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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UGUI OnClick Event! 1 Answer

GraphicRaycaster Blocking, priority - uGUI 0 Answers

[4.6 gui] Getting dimensions of 2D UI object (button for example) 2 Answers

(Unity 4.6) How to raycast against uGUI objects from an arbitrary screen/canvas position 2 Answers

get ugui prefab's child 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges