5
« on: April 12, 2014, 07:22:03 AM »
I need to check whether the specific widget is pressed or not each frame. What is the best way of doing this? Seems like a trivial task but I cannot figure out a perfect solution.
What i have now is this code, but the problem is that the FLY button is not always released when multiple different buttons are pressed at the same time if I use Unity Remote. It seems to work OK on device. Is my solution OK then?
using UnityEngine;
using System.Collections;
public class FlyButton_NGUI : MonoBehaviour
{
public bool matchToInputSettings;
public string buttonName;
private CrossPlatformInput.VirtualButton _flyVirtualButton;
private bool _isFlyPressed;
void OnEnable()
{
_flyVirtualButton = new CrossPlatformInput.VirtualButton(buttonName, matchToInputSettings);
}
void OnDisable()
{
_flyVirtualButton.Remove();
}
void OnPress(bool isDown)
{
print("OnPress : " + isDown);
_isFlyPressed = isDown;
}
void Update()
{
if (_isFlyPressed)
{
_flyVirtualButton.Pressed();
} else {
_flyVirtualButton.Released();
}
}
}