【问题标题】:multi-touch in the unity game not working统一游戏中的多点触控不起作用
【发布时间】:2015-06-30 19:19:36
【问题描述】:

我关注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】:

    您正在使用事件处理程序的接口。它没有实现自己的多点触控功能,因此您必须制作自己的触控逻辑。在大多数情况下,这是一种 hacky 方式。制作一个数组或触摸输入列表并为其提供案例。

    Unity3D Forum - Event System

    单击链接并检查答案编号 5。答案是一种 hacky 方式。因为事件接口正在将 EventHandler 添加到您为脚本拥有的任何游戏对象中。但是您总是需要告诉游戏引擎您接受多个输入

    【讨论】:

      猜你喜欢
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      • 2021-07-19
      相关资源
      最近更新 更多