0
我在Android 2D的Unity 2D中制作了一个类似Flappy Bird的游戏。我工作的&在我的设备上运行,但contsols有一个问题:如果我点击屏幕上的鸟襟翼和飞蝇,但是如果我拿着屏幕上的鸟继续上去和上升..我只想感觉到一个挖掘。 有我的代码:统一:FlappyBird控件不能在Android上工作,我应该怎么做?
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;
}
}
感谢您的答案,但有一个问题: 我试过这个:if touchCount == 1 - > cangoup = false,如果touchCount == 1 - > cangoup = true 我将所有didFlap改为cangoup。 我希望游戏在PC和Android运行这两个,但如果我离开,如果touchCount == 1 - > cangoup = false且如果touchCount == 1 - > cangoup = true在代码中的鸟拍摄出来的天空因为如果touchCount == 0的cangoup是变为真实发生这种情况:如果(cangoup){ \t \t \t rigidbody2D.AddForce(Vector2.up * flapSpeed); \t \t \t animator.SetTrigger( “DoFlap”); cangoup = false; } 对不起,我英文不好:) – 2014-12-07 10:30:05
没有这不是我的意思,你应该离开瓣独自您只需添加到您现有的代码,如果不改变它在您的更新做(input.touchcount == 0)cangoup =真;如果(didflap)你把它如果(cangoup){你的代码和cangoup = FALSE;}不要删除任何东西,或从你的COSE改变任何东西只是这些添加 – 2014-12-07 10:41:14