Unity 搭配 GUITexture 實現簡易觸控功能
細節請參考這些網站:
觸控數量:http://game.ceeger.com/Script/Input/Input.touchCount.html
觸控列表:http://game.ceeger.com/Script/Input/Input.touches.html
獲取觸控:http://game.ceeger.com/Script/Input/Input.GetTouch.html
以模擬機的形式測試功能,並觀察Print出的資訊。
獲取觸控:http://game.ceeger.com/Script/Input/Input.GetTouch.html
![]() |
新增GUITexture物件 |
![]() |
使用這個程式碼例子 |
![]() |
將物件指向給宣告的容器 |
#pragma strictvar touchGuiTexture : GUITexture;function Update () {// 宣告 nowTouchCount 為 目前觸控數量var nowTouchCount = Input.touchCount;// 假使 觸控數量大於 0if (nowTouchCount > 0){for (var i = 0; i < nowTouchCount;++i) {// 假使 觸控點 觸控起始if (Input.GetTouch(i).phase == TouchPhase.Began) {print("觸控點"+ i +"起始");}// 假使 觸控點 觸控離開if (Input.GetTouch(i).phase == TouchPhase.Ended) {print("觸控點"+ i +"離開");}// 假使 碰觸點 觸控移動 且 位置與touchGuiTexture接觸if (Input.GetTouch(i).phase == TouchPhase.Moved && touchGuiTexture.HitTest(Input.GetTouch(i).position)) {print("碰觸到 touchGuiTexture");}}}}
留言
張貼留言