Unity2D Input.touches管理可同时拖动两行

时间:2019-04-19 11:26:29

标签: c# unity3d input touch

我正在在android设备中进行射击箭头游戏多人游戏,在其中根据绘制的线条进行射击。但是我需要在同一屏幕上显示2行,但我不知道实现该功能的正确方法是什么。 问题是Touches数组是静态的,并且在两个实例中是通用的,因此Index数组会更改,而我想控制的touch值也会更改。

我试图用1行渲染器为2个GameObject做1个脚本

  for (int i = 0; i < Input.touchCount; i++)
            {
                if (Input.GetTouch(i).phase == TouchPhase.Began)
                {
                    if (touchIndex == -1)
                        touchIndex = Input.GetTouch(i).fingerId;

                    startPointLine = Camera.main.ScreenToWorldPoint(Input.GetTouch(touchIndex).position);

                }
//this if for the RIGHT half screen management
                if (Input.GetTouch(i).phase == TouchPhase.Moved && (TouchHalfRightScreen && IsRightDraggingZone))
                {

                    endPointLine = Camera.main.ScreenToWorldPoint(Input.GetTouch(touchIndex).position); 
                    Dragging();
                }
//this if for the LEFT half screen management
                if (Input.GetTouch(i).phase == TouchPhase.Moved && (!TouchHalfRightScreen && !IsRightDraggingZone))
                {
                    if (Input.touchCount == 1 && touchIndex == 1)
                        touchIndex--;
                    endPointLine = Camera.main.ScreenToWorldPoint(Input.GetTouch(touchIndex).position); 
                    Dragging();
                }
                if (Input.GetTouch(i).phase == TouchPhase.Ended)
                {
                    //reset touchIndex
                    touchIndex = -1;
                    ClearLine();
                }
            }

我希望我保存在indexTouch中的触摸是我管理的,但是在游戏中,我在屏幕的两侧都进行了一条拉线,然后在另一侧添加了一条拉线,会发生什么?我绘制的第一行被冻结,但最后一行正在移动。

为了澄清一点,这是我要同时绘制的拖动线。 https://img2.androidappsapk.co/poster/9/d/7/com.stickmanarcher.stickmanfightinggames.archerygames.stickman_5.png

enter image description here

0 个答案:

没有答案