Unity:FlappyBird控制不在Android上工作,我该怎么做?

时间:2014-12-06 15:32:47

标签: android unity3d touch touchscreen flappy-bird-clone

我在Unity 2D for Android中制作了类似Flappy Bird的游戏。我在工作&在我的设备上运行,但是contsols有一个问题:如果我点击屏幕,鸟襟翼飞,但是如果我按住屏幕,鸟就会继续上升......我只想感觉一下。 有我的代码:

        if (Input.touchCount == 1) {
            didFlap = true;
        }

完整代码:

using UnityEngine;
using System.Collections;

public class BirdMovement : MonoBehaviour {

    Vector3 velocity = Vector3.zero;
    public float flapSpeed    = 100f;
    public float forwardSpeed = 1f;

    bool didFlap = false;

    Animator animator;

    public bool dead = false;
    float deathCooldown;

    public bool godMode = false;

    // Use this for initialization
    void Start () {
        animator = transform.GetComponentInChildren<Animator>();

        if(animator == null) {
            Debug.LogError("Didn't find animator!");
        }
    }

    // Do Graphic & Input updates here
    void Update() {
        if(dead) {
            deathCooldown -= Time.deltaTime;

            if(deathCooldown <= 0) {
                if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
                    Application.LoadLevel( Application.loadedLevel );
                }
            }
        }
        else {
            if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
                didFlap = true;
            }
            if (Input.touchCount == 1) {
                didFlap = true;
            }

        }
    }


    // Do physics engine updates here
    void FixedUpdate () {

        if(dead)
            return;

        rigidbody2D.AddForce( Vector2.right * forwardSpeed );

        if(didFlap) {
            rigidbody2D.AddForce( Vector2.up * flapSpeed );
            animator.SetTrigger("DoFlap");


            didFlap = false;
        }

        if(rigidbody2D.velocity.y > 0) {
            transform.rotation = Quaternion.Euler(0, 0, 0);
        }
        else {
            float angle = Mathf.Lerp (0, -90, (-rigidbody2D.velocity.y / 3f) );
            transform.rotation = Quaternion.Euler(0, 0, angle);
        }
    }

    void OnCollisionEnter2D(Collision2D collision) {
        if(godMode)
            return;

        animator.SetTrigger("Death");
        dead = true;
        deathCooldown = 0.5f;
    }
}

1 个答案:

答案 0 :(得分:1)

如果你想用touchcount做,我认为你应该做这样的事情在start中创建bool变量cangoup = true 问

if (input.touchcount==0) 
   Cangoup=true;

而didflap语句应该是这样的 如果(cangoup) {//你写的一切 Cangoup = FALSE;} 我是从我的iphone写的,所以可能会有一些错误,但我相信你可以修复它们,我认为如果它不只是对答案的评论和不良回复,这对你有好处