0

I basically have this code. I got performance errors in unity3d when I tried to use OnMouseUp() function. I have no idea how to use Touch functions for android.

void OnMouseUp()
{
    DetectCollider.IfInMain = false;
    DetectCollider.Score = 0.00f;
    MainMenux.SetActive(false);
    Mech.transform.rotation = Quaternion.Euler(270, 180, 0);
    DetectCollider.Speed = 100;
    ScoreCountTurn = true;
}
cramopy
  • 3,459
  • 6
  • 28
  • 42
Tayfur Gazioglu
  • 109
  • 1
  • 11

2 Answers2

2

Try something like this. It should work for android also.

  void Update() {
    if (Input.GetMouseButtonUp(0)) 
    {
        DoStuff();
    }
  }

Or you can use Input.GetTouch(), and then check TouchPhase, instead of GetMouseButtonUp(). And support multitouching going this way.

  void Update() {
    if (Input.GetTouch(0).phase == TouchPhase.ended) 
    {
        DoStuff();
    }
  }
B4lto
  • 96
  • 3
0

Would have to use Touch events, there is complete example here: http://docs.unity3d.com/ScriptReference/Touch-phase.html

"TouchPhase.Ended" would be equal to OnMouseUp, but i dont think few OnMouseUp's would do any noticeable slowdowns to your game (you could check with profiler what if using most of the time and optimize those instead).

Also you would have to then implement raycasting to check which object gets hit by the touch position.

mgear
  • 1,333
  • 2
  • 22
  • 39