1
我下面this video here多點觸控的Unity遊戲不工作
的教程,一切工作正常,除了多點觸摸的部分。我有兩個按鈕,實際上是畫布上的兩個不同的圖像,但是當我使用其中一個時,我無法使用其他觸摸按鈕。我的每個按鈕都有這個腳本。
下面是代碼:
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;
}
}
統一的版本是4.6。