所以我正在制作游戏并在进行Android手机测试时进行测试。当我统一单击鼠标按钮时,播放器将向左或向右移动,这正是我想要的。但这并不能很好地转化为我的Android手机。如果我快速快速地在屏幕上快速敲击两个拇指,则KINDA可以工作,这会使播放器快速左右摆动,但是如果我正常地在屏幕上多次敲击,播放器只会向一个方向移动。也许只是android,也许是我的代码,我不确定。谁能为我提供一些启发,或者可能告诉我如何解决?
我已经尝试了不同的鼠标输入代码,例如Input.GetButtonDown(“ Fire1”)和其他东西。但是,使它统一工作的原因是当我在每个函数的末尾添加return时。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class playerController : MonoBehaviour {
private Rigidbody rb;
private Animator anim;
private bool left = false;
private bool right = false;
public static bool detect = false;
public float yspeed; //left or right from camera's vp
public float xSpeed = 55f; //down the road from camera's vp
[HideInInspector]
public bool crash = false;
public int slowSpeed;
private float respawnTimer = 3f;
void Start () {
rb = GetComponent<Rigidbody> ();
anim = GetComponent<Animator> ();
rb.velocity = new Vector3 (xSpeed, rb.velocity.y, rb.velocity.z);
}
void Update () {
Movement ();
Halt ();
}
public void Movement()
{
if (crash) {
left = false;
right = false;
scoreManager.scoreValue = 0;
}
detect = false;
if (Input.GetMouseButtonDown (0) && !left){
rb.velocity = new Vector3 (rb.velocity.x, yspeed, 0);
left = true;
right = false;
return;
}
if (Input.GetMouseButtonDown (0) && !right){
rb.velocity = new Vector3 (rb.velocity.x, -yspeed, 0);
right = true;
left = false;
return;
}
}
void OnTriggerEnter (Collider other)
{
if (!crash && other.gameObject.tag == ("wall")) {
crash = true;
anim.SetTrigger ("crash");
}
}
public void Halt()
{
if (crash && slowSpeed > 0) {
rb.velocity = new Vector3 (--slowSpeed, 0, 0);
Invoke ("Restart", respawnTimer);
}
}
public void Restart ()
{
Application.LoadLevel ("scene_01");
}
}