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 Ranger-Ori · Jan 15, 2014 at 08:00 AM · androidcolliderbuttoneventngui

NGUI UIButton Event question

Hi,

I have created 4 buttons which represent 4 direction arrows, Left, Right, Forward and Backwards.

I have a OnPress(bool isPress) function which checks which of the button were pressed and I send information about my x and y axis.

This is the function:

     private static int x = 0;
     private static int y = 0;
     private string currentArrow = "none";
     private Vector2 currentPos = Vector2.zero;
 
     void OnPress(bool isDown)
     {
         Debug.Log("Called " + gameObject.name + " press state: "+isDown);
         if (isDown)
         {
             switch (gameObject.name)
             {
                 case "Up":
                     y = 1;
                     x = 0;
                     break;
                 case "Down":
                     y = -1;
                     x = 0;
                     break;
                 case "Right":
                     x = 1;
                     y = 0;
                     break;
                 case "Left":
                     x = -1;
                     y = 0;
                     break;
                 default:
                     Debug.Log("Error in name");
                     break;
             }
             currentArrow = gameObject.name;
             currentPos = gameObject.transform.position;
         }
         else
         {
             x = 0;
             y = 0;
         }
 
         SetValues(x, y);
     }

This works just fine,

However, when my mouse is pressing a button, and I want it to move while it is pressed, to another collider, and activate it, I can't since I didn't release the last button.

Any idea on how to do it?

I've tried to send messages by myself to OnPress with a false parameter to do it manually, but it still doesn't work right..

I've also tried to use OnHover, but I work with an android device, so it's irrelevant...

Comment
Add comment · Show 3
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 GameVortex · Jan 15, 2014 at 08:38 AM 0
Share

So you want a sort of drag and drop functionality? Have you checked out NGUIs "Example X - Character" scene which has a drag an drop example?

avatar image Ranger-Ori · Jan 15, 2014 at 08:42 AM 0
Share

Not exactly my intentions, I want to move my finger to these 4 arrows, without releasing my touch input, and that NGUI will accept it as an event as soon as I enter a collider.

I can implement this with Unity's regular GUI, but it's a bit frustrating...

can NGUI handle my request?

avatar image GameVortex · Jan 15, 2014 at 09:06 AM 0
Share

Oh, then I understand what you want. NGUI can do this. Check out my answer below.

1 Reply

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

Answer by GameVortex · Jan 15, 2014 at 09:07 AM

To enable this functionality, go to the UICamera and uncheck the value "Sticky Press". This enables press events for multiple GameObjects instead of just the original pressed one. It is explained better in the comments for the value in the UICamera script.

Comment
Add comment · Show 3 · 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 Ranger-Ori · Jan 15, 2014 at 09:15 AM 0
Share

Great, thanks! it works now. One question, let's assume I want to Sticky function to work with other objects, what do I do? create two seperate cameras?

avatar image GameVortex · Jan 15, 2014 at 09:18 AM 1
Share

It depends. If the 4 arrow buttons are available at the same time as the other Objects then I think you need to use two cameras yes, but I would not recommend adding multiple cameras only for that.

If the 4 arrow are in its own menu/panel and not visible when the other buttons are visible then you can activate and deactivate Sticky Press through code when you change your panels/menus.

Also, for future support questions about NGUI I recommend the **NGUI forum** where the developer Aren$$anonymous$$ook is very active and helpful.

avatar image Ranger-Ori · Jan 15, 2014 at 09:27 AM 0
Share

Thanks, I'll keep that in $$anonymous$$d.

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

19 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

Related Questions

Android Button With Raycast 3 Answers

Android: Search button event 0 Answers

NGUI: Button don't detect input if parent change position on-screen? 1 Answer

how do i use GUI buttons with a android device(tablet) 2 Answers

Button Touch for Android 2 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