Mobile 统一tap移动问题

Mobile 统一tap移动问题,mobile,unity3d,tap,Mobile,Unity3d,Tap,我有一个简单的场景,当球员轻拍时,球的方向改变了90度; 我的代码可以工作,但并不完美,主要问题是“点击”检测 需要使用corroutine在点击之间进行暂停,但是0.25秒的暂停时间太大,在某些情况下响应时间很慢,但是如果试图减少暂停时间,它运行代码的速度会很快,以至于不再与点击不同; 我也尝试过使用touch.phase==start和touch.phase.stative,但这也不起作用 我想在你轻触时达到效果,它会改变方向一次,即使你按住它 有谁有更好的办法来检测水龙头吗 using U

我有一个简单的场景,当球员轻拍时,球的方向改变了90度; 我的代码可以工作,但并不完美,主要问题是“点击”检测

需要使用
corroutine
在点击之间进行暂停,但是
0.25秒的暂停时间太大,在某些情况下响应时间很慢,但是如果试图减少暂停时间,它运行代码的速度会很快,以至于不再与点击不同;
我也尝试过使用
touch.phase==start
touch.phase.stative
,但这也不起作用

我想在你轻触时达到效果,它会改变方向一次,即使你按住它

有谁有更好的办法来检测水龙头吗

using UnityEngine;

using System.Collections;


public class playerController : MonoBehaviour {

public float speed = 2f;
public float tapPauseTime = .25f;
Rigidbody rb;
bool timerOn;
bool goingRight;


void Awake(){

    rb = GetComponent<Rigidbody> ();
    timerOn = false;
    goingRight = false;
}

// Update is called once per frame
void Update () 
{

    if (Input.touchCount == 1 && !timerOn && !goingRight) {

            rb.velocity = Vector3.zero;
            rb.angularVelocity = Vector3.zero;
            rb.velocity = new Vector3 (speed, 0, 0);
            timerOn = true;
            goingRight = true;
            StartCoroutine(TapPause());
        }

    if(Input.touchCount == 1 && !timerOn && goingRight)
        {
            rb.velocity = Vector3.zero;
            rb.angularVelocity = Vector3.zero;
            rb.velocity = new Vector3(0,0,speed);
            timerOn=true;
            goingRight = false;
            StartCoroutine(TapPause());
        }


}

IEnumerator TapPause(){
    yield return new WaitForSeconds(tapPauseTime);
    timerOn = false;
}
使用UnityEngine;
使用系统集合;
公共类玩家控制器:单行为{
公共浮动速度=2f;
公共浮动时间=0.25f;
刚体rb;
布尔泰姆隆;
布尔走对了;
无效唤醒(){
rb=GetComponent();
timerOn=false;
正确=错误;
}
//每帧调用一次更新
无效更新()
{
如果(Input.touchCount==1&&!timerOn&&!goingRight){
rb.速度=矢量3.0;
rb.角速度=矢量3.0;
rb.velocity=新矢量3(速度,0,0);
timerOn=true;
正确=正确;
启动例行程序(TapPause());
}
if(Input.touchCount==1&&!timerOn&&goingRight)
{
rb.速度=矢量3.0;
rb.角速度=矢量3.0;
rb.velocity=新矢量3(0,0,速度);
timerOn=true;
正确=错误;
启动例行程序(TapPause());
}
}
IEnumerator TapPause(){
返回新的WaitForSeconds(tapPauseTime);
timerOn=false;
}

}如果您只关心单触事件(即没有多触),则
Input
中的所有鼠标处理程序都会模拟第一次触摸。因此,您可以使用
Input.GetMouseButtonDown(0)
来确定何时有触摸。此功能仅在鼠标按下(或在您的情况下,触摸)时返回真帧,并且在松开并再次按下按钮之前不会再次返回真帧。您可以将if语句中的
Input.touchCount==1
替换为
Input.GetMouseButtonDown(0)
来尝试此操作。

太好了,它就像一个符咒:)这正是我想要的,谢谢!