unity 捕捉屏幕的触控

unity 捕捉屏幕的触控

在andriod手机HTC Z710e测试下来,最多可以支持4根手指的触控,超出4根的不会再反应。

#pragma strict

var imgBG : Texture2D;
var smallImg : Texture2D;

function Start () {

}

function Update () {

}

function OnGUI(){
	//set screen background image
	GUI.DrawTexture(Rect(0,0,540,960),imgBG);
	
	//get touch count
	var count=Input.touchCount;
	for(var i=0;i<count;i++){
		var iPos = Input.GetTouch(i).position;//get touch position
		var x = iPos.x;
		var y = iPos.y;
		GUI.DrawTexture(Rect(x,960-y,48,48),smallImg);
		GUI.Label(Rect(x,960-y-100,200,40),"(x,y)="+x+","+y);
	}
	
	if(GUI.Button(Rect(0,0,100,40),"Quit")){
		Application.Quit();
	}
}

猜你喜欢

转载自stephen830.iteye.com/blog/2036960