首先在start()中开启触摸方法的使用:
void start()
{
//开启多点触摸
Input.multiTouchEnabled=true;
}
然后在每一帧中对触摸方式进行判断:
void Update()
{
//判断单点触摸
if(Input.touchCount==1)
{
//触摸对象
Touch.touch=Input.touches[0];
//触摸位置
Debug.Log(touch.position);
//触摸阶段
switch(touch.phase)
{
case TouchPhase.Began:
break;
case TouchPhase.Moved: //移动时
break;
case TouchPhase.Stationary: //静止时
break;
case TouchPhase.Ended: //结束时
break;
case TouchPhase.Canceled:
break;
}
}
//判断多点触摸
if(Input.touchCount==2)
{
//触摸对象
Touch.touch1=Input.touches[0];
Touch.touch2=Input.touches[1];
//触摸位置
Debug.Log(touch1.position);
Debug.Log(touch2.position);
//触摸阶段
switch(touch1.phase)
{
case TouchPhase.Began:
break;
case TouchPhase.Moved: //移动时
break;
case TouchPhase.Stationary: //静止时
break;
case TouchPhase.Ended: //结束时
break;
case TouchPhase.Canceled:
break;
}
}
}