【发布时间】:2016-11-15 01:52:09
【问题描述】:
我创建了这个脚本来检测向上和向下滑动。它需要做的就是更改 UI 文本..
脚本如下:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TouchControls : MonoBehaviour
{
private Vector2 startPos;
Text instruction;
void start() {
instruction = GetComponent<Text>();
}
float swipeValue = 0.0f;
void Update()
{
#if UNITY_ANDROID
if (Input.touchCount > 0){
Touch touch = Input.touches[0];
if(touch.phase == TouchPhase.Began){
startPos = touch.position;
}
else if(touch.phase == TouchPhase.Ended){
swipeValue = Mathf.Sign(touch.position.y - startPos.y);
if (swipeValue > 0){//up swipe
instruction.text="UP";
}
else if (swipeValue < 0){//down swipe
instruction.text="DOWN";
}
}
}
#endif
}
}
它不工作,我不明白为什么?有什么帮助吗?
【问题讨论】: