Under NGUI 3, what would be the best way to improve touch detection? I'm using the fallthrough and NGUI OnPress/OnClick in my main program to detect game clicks in a mobile game.
UICamera.fallThrough = this.gameObject;
public void OnClick()
{
bool mouseClick = true;
DetectMouseClick(mouseClick);
}
public void OnPress(bool isPressed)
{
DetectMouseClick(isPressed);
}
public void MoveHitObject(RaycastHit hit)
{
hitObject.gameObject.transform.position = hit.transform.position;
hitObject.IsActive = true;
}
public void DetectMouseClick(bool Pressed)
{
if (!enableGameClickTimer && !isPaused)
{
RaycastHit hit;
Ray ray = gameCamera.ScreenPointToRay(UICamera.lastEventPosition);
if (Physics.Raycast(ray, out hit))
{
MoveHitObject(hit);
switch (hit.transform.tag)
{
case "Ground":
case "Brick":
PurchaseBrick();
break;
}
} else
{
PurchaseBrick();
}
enableGameClickTimer = true;
}
}
When either is detected, a ray is cast into the game world and an object moved to encounter other objects that the touch might have intercepted. However, my testers are reporting that
this only works roughly half the time. Touch seems to be spotty, but the game relies on it. What can I do to improve the odds that an object is detected properly?