Reputation: 325
I'm creating a jetpack (mobile) controller where left joystick is used to control forward and backward movements and right joystick is used to control rotation and upward movements. What I want is player to go upwards whenever user is touching the right joystick even if horizontal && vertical axes both return zero. So if there is a finger on the right joystick player goes up similar to GetButton or GetKey(some keycode).
Upvotes: 0
Views: 1139
Reputation: 325
Hope this helps somebody in the future:
I found out there is OnPointerUp and OnPointerDown methods that can be used to check if joystick is pressed or not. Easiest way for me to use those were to change a few things in Standard Assets > Utility > Joystick.cs. This is how those methods look like after my modifications:
public void OnPointerUp(PointerEventData data)
{
transform.position = m_StartPos;
UpdateVirtualAxes(m_StartPos);
if (data.rawPointerPress.name == "MobileJoystick_right") {
rightJoystickPressed = false;
}
}
public void OnPointerDown(PointerEventData data) {
if (data.pointerEnter.name == "MobileJoystick_right") {
rightJoystickPressed = true;
}
}
So basically I just added the If-statements. Now I can access the rightJoystickPressed boolean from any other script to check if joystick is being pressed even if it is not moved.
Upvotes: 1