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
5
Question by EMOTION-THEORY · Feb 02, 2015 at 11:23 PM · c#uiinspector

Button OnClick inspector - how do I do this?

The Unity 4.6 UI Button has a neat OnClick inspector where you can specify a GameObject, a Script, and a Function to call along with parameters - whether they're primitive types you can place in, or MonoBehaviour references. You can assign Properties too.

alt text

This is absolutely incredible.

Does anybody know how I can replicate such a thing in the inspector? Is there a way to "borrow" this functionality? Or is the source code for it available somewhere so it may be replicated?

Thank you so much for any help or response.

Comment
Add comment · Show 1
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 SnotE101 · Feb 02, 2015 at 11:45 PM 0
Share

Not sure about source code. But when defining an RPC you have to type in the functions name with a string. Go check that out maybe. Sorry I couldn't be anymore of a help.

3 Replies

· Add your reply
  • Sort: 
avatar image
12

Answer by emayberry · Mar 17, 2015 at 03:54 PM

Hopefully you've found your answer, but for anybody else looking around this is actually very simple to do. The inspector is capable of displaying any event that inherits from UnityEvent, so you can either add an existing event type or make your own as follows:

  using UnityEngine;
  using UnityEngine.Events;
  
  public class EventTest : MonoBehaviour {
 
     [Serializable]
     public class MyEventType : UnityEvent { }
 
     public MyEventType OnEvent;
 
 }
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 chorusgames · Mar 27, 2015 at 06:28 AM 0
Share

cool it works great! now how exactly do i use the OnEvent variable and make it trigger all the functions thats added inside it?

avatar image Kevin Ambruster · Jul 10, 2015 at 08:36 PM 0
Share

To call any of the events you need to call the Invoke() method of the UnityEvent.`OnEvent.Invoke();`

avatar image OminStyle · Sep 17, 2015 at 03:14 AM 0
Share

This is so useful! Thank you!!

avatar image WickedFreaK · Apr 16, 2018 at 10:49 AM 0
Share

[System.Serializable] it is now

avatar image
0

Answer by FezAstron · Feb 03, 2015 at 03:07 AM

Perhaps you're thinking about Event Trigger that you can add as a component. It has all the features an Interactive UI would need like PointerEnter(aka MouseEnter) or PointerUp(aka MouseUp). Just add it through the inspector by searching for "Event System". Now I may be thinking something completely different than what you're asking so correct me if I'm wrong. =)

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
0

Answer by tcoursow · Dec 13, 2016 at 04:41 PM

You could also extend from the Unity Button class and only use your button type in your project like this:

 [AddComponentMenu("UI/UI Button", 30)]
 public class UIButton : UnityEngine.UI.Button
 {
     public void Click()
     {
         onClick.Invoke();
     }
 }

Now "Click" should show up in the inspector

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

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

28 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 avatar image avatar image

Related Questions

How to make a single word in a Text object clickable / have hover. 2 Answers

How do I get the Inspector to show Event boxes when extending Unity objects? 0 Answers

Inspector changes set TextMeshPro values on play 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 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