简体中文 | English


M系列一体机右侧有一个触摸板,该触摸板响应的是标准TouchPad和Mouse的消息,它只支持单点触摸。

在Unity3D中,可以使用Input.touchCount来判断是否有Touch。然后通过Input.GetTouch(0)获得这个Touch的信息,包括位置、大小等。

此外触摸板还响应了Mouse消息,所以也可以通过Input.GetMouseButton(0)得知是否有Touch,而Input.mousePosition则是当前Touch的位置。


下面的脚本挂在一个Text下面就可以输出这些消息。

using UnityEngine;

using UnityEngine.UI;

using System.Collections;


public class TouchPad : MonoBehaviour

{


Text txt;


// Use this for initialization

void Start()

{

txt = GetComponent<Text>();

}


// Update is called once per frame

void Update()

{

string msg = "touch: ";



if(Input.touchCount)

{

Touch tch = Input.GetTouch(0);

msg += tch.position.x + "," + tch.position.y + "," + tch.deltaPosition.x + "," + tch.deltaPosition.y + "," + tch.radius + "\n";

}

else

{

msg += "none\n";

}


Vector3 mouse_position = Input.mousePosition;

bool btn0 = Input.GetMouseButton(0);


msg += btn0.ToString() + " " + mouse_position.x + "," + mouse_position.y + "," + mouse_position.z + "\n";


txt.text = msg;

}

}



Copyright © 2015deepoon.com,All Rights Reserved 沪ICP备15019466号-1 上海乐相科技有限公司