- Home /
multiple GUI.Buttons at the same time
hi there, i wanted to do a fast GUI.Button menu and use it as input for android devices...
so i have RepeatButtons w,a,s,d and public static booleans: Wispressed, Aispressed and so on
if (GUI.RepeatButton(new Rect(x1-50, y1, 50, 50), "A")) {a=true;} else a=false;
my problem is, that i can't press many buttons at the same time. if i am pressing "D" do walk forward and than press "W" to jump while walking (its a 2d platformer) the jump is not beeing done...
some ideas? thanks for help!
i allready had a look on Input.touch but i don't really understood it :/
what shoud be the code for a Gui button-like thing, that i can touch while touching others of the same kind?
i thought buttons would be a nice way, because i can test the funktionality on the pc too...
Answer by Shaander1 · Jan 15, 2013 at 08:37 PM
Here's what I could whip up, turn your current GUI Buttons into GUITextures then do the following in OnGUI:
// Set these to the proper rect you have defined in your code.
Rect wRect = new Rect( 0, 0, 50, 50 );
Rect aRect = new Rect( 0, 0, 50, 50 );
Rect sRect = new Rect( 0, 0, 50, 50 );
Rect dRect = new Rect( 0, 0, 50, 50 );
bool wPress = false;
bool aPress = false;
bool sPress = false;
bool dPress = false;
foreach ( Touch t in Input.touches )
{
if ( wRect.Contains( t.position ) )
wPress = true;
else
wPress = false;
if ( aRect.Contains( t.position ) )
aPress = true;
else
aPress = false;
if ( sRect.Contains( t.position ) )
sPress = true;
else
sPress = false;
if ( dRect.Contains( t.position ) )
dPress = true;
else
dPress = false;
}
Hey there is no compilation error and i have added this code in OnGUI but gui buttons are not shown.
Doing this in 2016, you should really use the UI... https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-button?playlist=17111
Your answer
Follow this Question
Related Questions
GUI Button appears when Paused 1 Answer
(Unity 4.6) Button animations 1 Answer
Make more buttons appear, on button click. 1 Answer
GUI Button Not Displaying? 1 Answer
Toggling multiple button states 2 Answers