N
N
NickName73312018-05-22 18:17:42
C++ / C#
NickName7331, 2018-05-22 18:17:42

Unity (C#) - How to read a finger touch on a button?

How to count finger touch on a button (GUI)? Here is the code:

void OnGUI () {
    GUI.Box(new Rect(550,572,400, 30), "");
    GUI.Label (new Rect(560,577,340,20), Message1);
    if(GUI.Button(new Rect(900,572,50,30), "ОК")) {
      gameObject.SetActive (false);
      Object.SetActive (false);
    }
  }

It works, but you need to click with the mouse, how to do the same, but by touching with your finger?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2018-05-22
@NickName7331

First, why are you using OnGUI? This is an ancient interface system that is now only used for debug buttons. Everyone has long switched to a new UI or plugins.
Secondly, finger taps on mobile phones for OnGUI should work exactly the same as in the editor, maybe your buttons are small and therefore the taps do not work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question