I’m using the Joystick script for all my inputs (mobile, buttons and axis) and I did a simple script to get input from multiple joysticks.
So, I’m doing the GetButton like this:
function GetButton(button : String)
{
var value : boolean;
if(useVirtualJoystick)
{
switch(button)
{
case "Fire1":
value = (buttons[0].tapCount > 0) == true;
break;
case "Fire2":
value = (buttons[1].tapCount > 0) == true;
break;
case "Fire3":
value = (buttons[3].tapCount > 0) == true;
break;
}
}
else
{
value = (Input.GetButton(button) == true);
}
return value;
}
I’m wondering how can I make something like this but to get a single button press and return true then starting returning false… I just need to know a logic on how this works…
Okay, I got it, just made one more modification on Joystick.js:
//...
var firstTouch : boolean;
//...
// then inside the update and its for:
for (var i : int = 0; i < count; i++)
{
var touch : Touch = Input.GetTouch (i);
var guiTouchPos : Vector2 = touch.position - guiTouchOffset;
var shouldLatchFinger = false;
if (touchPad)
{
if (touchZone.Contains (touch.position))
{
shouldLatchFinger = true;
if(touch.phase == TouchPhase.Began) // <---
firstTouch = true; // <---
else
firstTouch = false; // <---
}
}
//...
And, my InputManager’s GetButtonDown goes like this:
function GetButtonDown(button : String)
{
var value : boolean;
if(useVirtualJoystick)
{
switch(button)
{
case "Fire1":
value = (buttons[0].firstTouch);
break;
case "Fire2":
value = (buttons[1].firstTouch);
break;
case "Fire3":
value = (buttons[3].firstTouch);
break;
default:
break;
}
}
else
{
value = (Input.GetButtonDown(button) == true);
}
return value;
}