统一游戏中的多点触控不起作用

问题描述 投票:1回答:1

我正在关注this video here

除多点触控部分外,本教程和其他所有内容都工作正常。我有两个按钮,它们实际上是画布上的两个不同图像,但是当我使用一个按钮时,不能使用另一个触摸按钮。我的每个按钮都有此脚本。

这里是代码:

    using UnityEngine.UI;
    using UnityEngine.EventSystems;
    using System.Collections;

    public class SimpleTouchShoot : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
    {
      private bool touched;
      private int pointerID;
      private bool canFire;

     void Awake()
     {
         touched = false;
         canFire = false;
     }

     public void  OnPointerDown (PointerEventData data)
     {
         if(!touched)
         {
             touched = true;
             pointerID = data.pointerId;
             canFire = true;
         }

     }

     public void OnPointerUp (PointerEventData data)
     {
         if(data.pointerId == pointerID)
         {
             touched = false;
             canFire = false;
         }

     }

     public bool CanFire ()
     {
         return canFire;
     }
 }

Unity的版本是4.6。

c# unity3d touch multi-touch
1个回答
4
投票

您正在将接口用于事件处理程序。它没有实现自己的多点触摸功能,因此您必须自己制定触摸逻辑。在大多数情况下,这是一种不明智的做法。制作一个数组或一个触摸输入列表,并为其提供说明。

Unity3D Forum - Event System

单击链接并查看答案编号5。答案是一种骇人听闻的方法。因为事件接口会将EventHandler添加到脚本的任何GameObject中。但是,您总是需要告诉游戏引擎您接受多个输入

© www.soinside.com 2019 - 2024. All rights reserved.