I have three 2D buttons in the GUI - left, right, up. And I need to implement simultaneous button presses. Well, for example, simultaneously press the 'right' and 'up' (Jump), that would simultaneously move to the right and jump. I ask those who know to throw off the code itself, just as in theory I know how to do it. Here is an example of code that I found on the forum How to implement Multi Touch for Unity Android (It is attached to the buttons in the Update cycle and it did not work for me).

//C# using UnityEngine; using System.Collections; public class MobileInput : MonoBehaviour { public void Update() { //Касания Touch[] touches = Input.touches; //Цикл for (int i = 0; i < touches.Length; i++) { Touch touch = touches[i]; if (touch.phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit; Debug.DrawRay(ray.origin, ray.direction, Color.cyan); //Рейкаст if (Physics.Raycast(ray, out hit, 100)) { if (hit.collider.gameObject.tag == "Fruit" && !Values.gamePaused) { } } } } } } 

    1 answer 1

    The example is taken from the documentation ( https://unity3d.com/learn/tutorials/topics/mobile-touch/multi-touch-input )

     public class TouchTest : MonoBehaviour { void Update () { Touch myTouch = Input.GetTouch(0); Touch[] myTouches = Input.touches; for(int i = 0; i < Input.touchCount; i++) { //здесь делаешь все с твоими касаниями, которые хранятся в myTouches } } } 

    Try searching on the Internet before asking ... This was the first search result for "Multitouch Unity"

    • I saw this, but did not understand, it needs to be fixed to a button, or something needs to be modified, type checking the location of the wheelbarrow and comparing it with the coordinates of the button? - Andrey Probochkin
    • You create a TouchTest script, insert the text above instead of a class. Then what exactly do you need to do, I do not know, I am not an oracle. :) If you have a button on the screen that you have to click on, then I don’t know she’s 3d on stage or 2D. If it is 2D, then I do not know it is implemented through the GUI or NewGUI. Again, I am not an oracle. If you want a more accurate answer, you need to give more complete information. I answered your question above more than exactly :) - Andrew
    • Ok, I have a few 2d buttons in the GUI that need to be multitouch. When you press any button, by means of multitouch, it is necessary that some action would be performed, well, for example, to enter text. - Andrey Probochkin
    • He initially should support multitouch, as far as I know. Just when you draw at the same time in the GUI and ask what it should do, for example, in the update if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture)) Debug.Log("Clicked button 1"); . Just create the right amount of buttons. PS: this is an outdated technology and if you need a lot of interface elements to draw, then if possible use NewGUI. - Andrew
    • one
      Mark the answer correct if the problem is solved - Andrew