输入不是来自触摸板认可 [英] Input not recognised from touchpad

查看:173
本文介绍了输入不是来自触摸板认可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想延长这一无障碍一个球教程包括一个计时器,并允许他们是否赢得了用户通过敲击触摸板再试或时间用完。

这工作正常,如果在时间耗尽( //情况下A 以下),但不是如果玩家获胜( //情况B 以下),水龙头似乎不能得到认可。最终的信息出现在两种情况下,所以它肯定是深远的部分,但我猜测,该计划没有达到与注释的部分 //重新设置自来水,但我不能肯定。

任何想法AP preciated。

我的的PlayerController 脚本:

 无效的start()
{
    的timeleft = 5;
    RB = GetComponent<&刚体GT;();
    计数= 0;
    winText.text =;
    SetCountText();
}
无效更新()
{
    如果(!GAMEOVER){
        的timeleft - = Time.deltaTime;
    }
    timerText.text = timeLeft.ToString(0.00);
    如果(的timeleft℃,){
        赢家= FALSE;
        GAMEOVER(冠军);
    }
}
无效GAMEOVER(布尔冠军)
{
    GAMEOVER = TRUE;
    timerText.text = - - ;
    字符串tryAgainString =点击触摸板再试一次。
    如果(!获得者){//情况A
        winText.text = + tryAgainString时间到了\\ n;
    }
    如果(冠军){//情况B
        winText.text =发挥好\\ n!+ tryAgainString;
    }
    //自来水复位
    如果(Input.GetMouseButtonDown(0)){
        Application.LoadLevel(0);
    }
}
无效FixedUpdate()
{
    浮moveHorizo​​ntal = Input.GetAxis(鼠标X);
    浮moveVertical = Input.GetAxis(鼠标Y);
    运动的Vector3 =新的Vector3(moveHorizo​​ntal,0.0,moveVertical);
    rb.AddForce(移动速度*);
}
无效OnTriggerEnter(撞机等)
{
    如果(other.gameObject.CompareTag(捡)){
        other.gameObject.SetActive(假);
        数=计+ 1;
        SetCountText();
        如果(!GAMEOVER){
            的timeleft + = 3;
        }
    }
}
无效SetCountText()
{
    如果(!GAMEOVER){
        countText.text =伯爵:+ count.ToString();
    }
    如果(计数> = 12){
        赢家= TRUE;
        GAMEOVER(冠军);
    }
}


解决方案

将一个在的debug.log方法SetCountText和输出的计计值。你可能永远不会打到12点关口。
确保所有的收藏品标签捡。

更新
你应该听在玩家输入更新方法。 FixedUpdate ,如果两个 FixedUpdate 电话之间发生的执行作为固定的更新的一部分,任何其他功能将错过玩家输入

因此​​,改变你的更新 GAMEOVER 方法如下:

 无效更新(){
    如果(GAMEOVER){
        如果(Input.GetMouseButtonDown(0)){
            Application.LoadLevel(0);
        }
    }其他{
        的timeleft - = Time.deltaTime;
        timerText.text = timeLeft.ToString(0.00);
        如果(的timeleft℃,){
            赢家= FALSE;
            GAMEOVER(冠军);
        }    }}
GAMEOVER无效(布尔冠军){
    GAMEOVER = TRUE;
    timerText.text = - - ;
    字符串tryAgainString =点击触摸板再试一次。
    如果(!获得者){//情况A
        winText.text = + tryAgainString时间到了\\ n;
    }
    如果(冠军){//情况B
        winText.text =发挥好\\ n!+ tryAgainString;
    }}

I am trying to extend this Roll-a-Ball tutorial to include a timer and allow the user to try again by tapping the touchpad whether they win or run out of time.

This works as expected if the time runs out (// case A below) but not if the player wins (// case B below), where the tap does not seem to be recognised. The end message appears in both cases so it is definitely reaching those parts but I'm guessing that the program is not reaching the section with the comment // reset on tap but am not certain.

Any ideas appreciated.

My PlayerController script:

void Start ()
{
    timeLeft = 5;
    rb = GetComponent<Rigidbody>();
    count = 0;
    winText.text = "";
    SetCountText ();
}
void Update()
{
    if (!gameOver) {
        timeLeft -= Time.deltaTime;
    }
    timerText.text = timeLeft.ToString ("0.00");
    if(timeLeft < 0) {
        winner = false;
        GameOver(winner);
    }
}
void GameOver(bool winner)
{
    gameOver = true;
    timerText.text = "-- --";
    string tryAgainString = "Tap the touch pad to try again.";
    if (!winner) { // case A
        winText.text = "Time's up.\n" + tryAgainString;
    }
    if (winner) { // case B
        winText.text = "Well played!\n" + tryAgainString;
    }
    // reset on tap
    if (Input.GetMouseButtonDown (0)) {
        Application.LoadLevel(0);
    }
} 
void FixedUpdate ()
{
    float moveHorizontal = Input.GetAxis ("Mouse X");
    float moveVertical = Input.GetAxis ("Mouse Y"); 
    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);    
    rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other) 
{
    if (other.gameObject.CompareTag ( "Pick Up")){
        other.gameObject.SetActive (false);
        count = count + 1;
        SetCountText ();
        if (!gameOver) {
            timeLeft += 3;
        }
    }
}   
void SetCountText ()
{
    if (!gameOver) {
        countText.text = "Count: " + count.ToString ();
    }
    if (count >= 12) {
        winner = true;
        GameOver(winner);
    }
}

解决方案

Put a Debug.Log in SetCountText method, and output the value of count count. You are probably never hitting the 12 point mark. Make sure all your collectibles have the tag " Pick Up".

Update You should listen for player input in Update method. FixedUpdate and any other functions that execute as part of Fixed Update will miss the player input if it happens between two FixedUpdate calls.

So change your Update and GameOver method as follows:

void Update() {
    if (gameOver) {
        if (Input.GetMouseButtonDown(0)) {
            Application.LoadLevel(0);
        }
    } else {
        timeLeft -= Time.deltaTime;
        timerText.text = timeLeft.ToString("0.00");
        if (timeLeft < 0) {
            winner = false;
            GameOver(winner);
        }

    }

}
void GameOver(bool winner) {
    gameOver = true;
    timerText.text = "-- --";
    string tryAgainString = "Tap the touch pad to try again.";
    if (!winner) { // case A
        winText.text = "Time's up.\n" + tryAgainString;
    }
    if (winner) { // case B
        winText.text = "Well played!\n" + tryAgainString;
    }

}

这篇关于输入不是来自触摸板认可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆