2
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

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 itself 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(); 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! :)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .