Pressing more than one GUI element at a time in Unity
I'm developing controls for a mobile platform; my GUI takes up the left,
center, and right thirds of the screen. When the player wants to jump,
they press the center button. My problem is that it seems that only one
GUI element is being allowed to be pressed at once (like the device has
only one mouse cursor that moves) rather than me being allowed to jump and
go right at the same time. My code:
// JavaScript
#pragma strict
static var guiLeft : int = 0;
static var guiRight : int = 0;
static var guiJump : int = 0;
function OnGUI () {
// leftarrow
if (GUI.RepeatButton (Rect (0,0,Screen.width/3,Screen.height), "",
GUIStyle.none)) {
guiLeft = 1;
}
else{
guiLeft = 0;
}
// right
if (GUI.RepeatButton (Rect
(Screen.width-Screen.width/3,0,Screen.width/3,Screen.height), "",
GUIStyle.none)) {
guiRight = 1;
}
else{
guiRight = 0;
}
// jump
if (GUI.RepeatButton (Rect
(Screen.width/3,0,(Screen.width/3)+2,Screen.height), "", GUIStyle.none)) {
guiJump = 1;
}
else{
guiJump = 0;
}
}
No comments:
Post a Comment