Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 FireHawkX · Oct 04, 2016 at 06:58 PM · androidbuttonhighlightbuttonstatesselected

Android Button : Select (highlight) by touch, before clicking.

I have a multiplatform game with dozens of buttons in many menus.

I used the animated buttons setup to have a normal state and highlight state. Highlight will most of the time resize the button with a nice anim AS WELL as make a dedicated text box appear with extra information. So far so good. Everything works perfectly on PC.

However, as I am testing my build on android, I cannot find how to access the "highlight" state since touching the screen = click and it execute the on click () associated.

What I need is a way to select a button when it is first touched, since selected = highlight (somewhat) then if it is touched (clicked) a second time while selected then to do the on click ( ) function.

I have a few theory on how to do it, but it would require recreating every of my 80 or so buttons as well as changing everything from using the Unity GUI system to make my own C# version which would take weeks.

I am also trying a few other way to achieve the same thing. One of which is using the "button.select()" to select the button on its first click. That works. problem is I cannot seem to write a way to do: "if (thisbutton.IsSelected == true)" that just refuses to work.

Comment
Add comment · Show 2
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 dev01definite · Oct 05, 2016 at 05:34 AM 0
Share

I suggest to use Unity UI. Easy to implement and have various events like OnClicked, OnRelease etc. Just edit its properties to your liking.

avatar image FireHawkX dev01definite · Oct 05, 2016 at 11:33 AM 0
Share

Thanks for the answer! :) However I am already using unity UI! the problem is that i cannot get the highlight state to display when using Android since there is no "mouse over" state when using a touch device!

2 Replies

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

Answer by FireHawkX · Nov 01, 2016 at 03:48 PM

Should anyone every come here looking for an answer to something similar, here is what i eventually managed to do :

I created a special button script that could either call the function directly if running on PC, or, if on a touchscreen it would select the button first based on its name, and if it was already selected, it would call the function.

   using UnityEngine.UI;

   (...)

   public void CallButton (string OriginalName) 
   //the function called when the button is clicked, the string is the name of the button in Unity
   {
     #if UNITY_STANDALONE || UNITY_WEBPLAYER  || UNITY_WEBGL
         ButtonFunction(); //IF on pc, call the function directly
     #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
     if (Static.ButtonSelectedName == OriginalName)
     {
         ButtonFunction(); //if on touch, and button is already selected, call function.
     }
     else
     {
         Static.ButtonSelectedName = OriginalName; 
              //update static STRING with the name of this button
         Button thisButton = GameObject.Find(OriginalName).GetComponent<Button>();
         thisButton.Select (); //Select (highlight) the button.
     }
     #endif
     }

 void ButtonFunction ()
 {
 //anything that your button actually needs to be doing
 }

This works on every single button in my project and enabled them to get selected with the first touch, then executed on the 2nd if its already selected. Hope it can help someone one day! :)

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 hoogemast · Oct 06, 2016 at 11:29 AM

You could create a specialized onclick method for the button that sets the ui element on hover first and then when the onclick method is called again the function is called.

so something like this.

 onClickCall
 {
 if (firstclick)
 {
 firstclick = false;
 //reset all other buttons set this button on hover
 //could be managed with a button class variable  (static) that stores all buttons
 }
 else
 {
 //call the function here
 firstclick = true; //reset the firstclick of this button again after function is called
 }
 }

when you click an object however you should reset all other buttons somehow (maybe an array or something that is looped through?)

Comment
Add comment · Show 1 · 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 FireHawkX · Oct 06, 2016 at 11:41 AM 0
Share

This is pretty much the way i was thinking of doing it... However, that means i must stop using the unityUI button on click () that i have... since all of my 80 something buttons have different things setup as their on click ()... and there are also many sliders and checkbox that uses the exact same animation mechanics.... many of which toggle the "set active" property of various gameobjects... that would mean having a seperate onclickcall.cs for every single buttons since each have a different function that is called... and that was exactly what i was trying to avoid... i already have over 90 .cs files in my game and didnt want to double that amount simply to fix the buttons...

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

103 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 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 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 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

Button highlight not intended on Android and iOS 0 Answers

How do I highlight multiple buttons at once? 1 Answer

GUI Texture Pause Button 0 Answers

How do I control the behavior of Android soft buttons (Immersive mode)? 1 Answer

how use specific for mobile button when we have 3 ? 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