Input.touches 触摸列表

static var touches : Touch[]

Description描述

Returns list of objects representing status of all touches during last frame (Read Only) (Allocates temporary variables).

返回代表上一帧所有的触摸状态的对象列表(只读)(分配临时变量)

Each entry represents a status of a finger touching the screen.

每个记录都代表着一个手指在屏幕上的触碰状态

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Update() {
		int fingerCount = 0;
		foreach (Touch touch in Input.touches) {
		if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
			fingerCount++;

		}
		if (fingerCount > 0)
			print("User has " + fingerCount + " finger(s) touching the screen");

	}
}
// Prints number of fingers touching the screen
//输出触摸在屏幕上的手指数量

function Update () {
	var fingerCount = 0;
	for (var touch : Touch in Input.touches) {
		if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
			fingerCount++;
	}
	if (fingerCount > 0)
		print ("User has " + fingerCount + " finger(s) touching the screen");
}
最后修改:2011年3月11日 Friday 19:07

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。