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
0
Question by N1nja · Jul 14, 2012 at 02:18 AM · buttondynamicnguionclick

NGUI Button Click Callback from external script.

I simply do not have the option to check if the button is clicked, was clicked, or being clicking using OnClick function within a MonoBehaviour attached to a button, instead I need something like buttonComponent button = GameObject.Find("button").GetComponent();

if(button.pressed) { BUTTON WAS PRESSED... CLICKED.. SAME THIng }

maybe those are not the right class names for NGUI but I never actually used it, just looking online for tutorials before I purchase it are not telling me if thats possible or not, and I simply dont wanna inest $90 for a GUI Tool that wont even do something as simple as that.. :{

I found a tutorial that lets me do something like button.text = "... NEW TEXT";

so surely it has some kind of boolean to check if its pressed or being clicked

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
1

Answer by whydoidoit · Jul 14, 2012 at 11:03 AM

You would just write your own handler for that - I do something similar for events that are fired when a button is pressed (which is not normal NGUI either).

 var isPressed = false;
 
 function OnPress(pressed : boolean) {
       isPressed = pressed;
 }
 

Or in my case (C#):

    public event Action Clicked = delegate {};

    void OnClick() {
        Clicked();
    }

    
Comment
Add comment · Show 8 · 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 sona.viswam · Feb 05, 2013 at 07:41 AM 0
Share

i have so many buttons. so please explain how to differntiate functions.

avatar image whydoidoit · Feb 05, 2013 at 08:56 AM 0
Share

You know there's a free version of NGUI you can try? And NGUI support is best asked on the NGUI forum.

You use UIButton$$anonymous$$essage scripts to send different Send$$anonymous$$essage calls, or you attach an event script like the one I put above (in C#) and do

  button1.GetComponent< SomeEventScriptYouWrote>().Clicked += SomeHandler;
avatar image sona.viswam · Feb 05, 2013 at 09:29 AM 0
Share

@whydoidoit: Thanks :)

avatar image Oi · Oct 07, 2013 at 12:18 PM 0
Share

Hi @whydoidoit,

I'm trying to use your approach to deal with a OnSelectionChange of PopUplist from NGUI but Unity tells me:

The type or namespace name `Action' could not be found

Any idea of why is this jappening?

avatar image whydoidoit · Oct 07, 2013 at 02:11 PM 0
Share

You need to declare it as System.Action or add a using System; to the top of the file.

Show more comments
avatar image
0

Answer by mrekuc · Aug 08, 2014 at 04:31 PM

If you attach the same script to all your buttons then just do something like this..

 void OnClick()
 {
     string button = gameObject.name;
     switch(button)
     {
         case "Button Name":
             if(Debug.isDebugBuild) Debug.Log("My Button was Clicked");
             break;
     }
 }

Create a new case for each button you haves name and it will trigger each independently.

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

9 People are following this question.

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

Related Questions

Best way to load a level depending on which game object is clicked 1 Answer

OnMouseUp interfering with NGUI OnClick Button 1 Answer

Button.onClick.AddListener(() => Attack()); isn't running function math correctly 1 Answer

onclick.addlistener only works once 0 Answers

My onclick action listeners I attach to my buttons as I instantiate them only work once 1 Answer


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