Input.touchCount static int touchCount;
Description
Number of touches. Guaranteed not to change throughout the frame. (Read Only)
PC上不能触摸,所以这个值总是为0。在小米手机上,经本人测试,为触摸在屏幕上的手指数量。所以我们一般要在检测触摸事件前加上一句判断
如
if(Input.touchCount>0)
{
if(Input.GetTouch(0).phase==TouchPhase.Began)
{
oldloc=Input.GetTouch(0).position;
touched=true;
}
}
在PC上若没有if(Input.touchCount>0)这句判断,由于没有触摸事件,所以Input.touchCount始终为0,Input.GetTouch(0)将出错。<