【发布时间】:2016-08-15 15:54:41
【问题描述】:
我正在开发一款 2D 游戏,现在我已经完成了! (幸福)。但我不能让它在android中移动。下面的代码有什么问题?
当我在 UNITY 控制台中运行应用程序时不会出现任何错误。
using UnityEngine;
using System.Collections;
public class Bee : MonoBehaviour {
public float velocity;
public Transform bee;
private Animator animator;
public bool isGrounded = true;
public float force;
public float jumpTime = 0.4f;
public float jumpDelay = 0.4f;
public bool jumped = false;
public Transform ground;
private Gerenciador gerenciador;
// Use this for initialization
void Start ()
{
gerenciador = FindObjectOfType (typeof(Gerenciador)) as Gerenciador;
animator = bee.GetComponent<Animator> ();
gerenciador.StartGame ();
}
// Update is called once per frame
void Update ()
{
Move();
}
void Move()
{
isGrounded = Physics2D.Linecast (bee.transform.position, ground.position, 1 << LayerMask.NameToLayer ("Floor"));
foreach (UnityEngine.Touch touch in Input.touches) {
if (this.GetComponent<GUITexture> ().HitTest (touch.position)) {
if (touch.phase != TouchPhase.Ended) {
if (this.name == "Right") {
animator.SetBool ("Run", true);
bee.transform.Translate (Vector2.right * velocity* Time.deltaTime);
bee.transform.eulerAngles = new Vector2 (0, 0);
}
if (this.name == "Left") {
animator.SetBool ("Run", true);
bee.transform.Translate (Vector2.right * velocity* Time.deltaTime);
bee.transform.eulerAngles = new Vector2 (0, 180);
}
if (this.name == "Up" && isGrounded && !jumped) {
animator.SetTrigger ("JumpB");
bee.GetComponent<Rigidbody2D> ().AddForce (transform.up * force);
jumpTime = jumpDelay;
jumped = true;
}
}
if (touch.phase == TouchPhase.Ended) {
animator.SetBool ("Run", false);
}
}
}
if (jumpTime >= 0f) {
jumpTime -= Time.deltaTime;
}
if (jumpTime <= 0 && isGrounded && jumped) {
animator.SetTrigger ("groundB");
jumped = false;
}
}
【问题讨论】:
-
尝试使用 Unity Remote 调试您的代码,您可以在 Google Play 上找到它。这个应用程序允许您在 Unity 编辑器中调试触摸。
-
只是一件小事,如果你想把它移植到 PC 上,将你的动作锁定到你的帧速率是个坏主意!
-
@Draken if for android =]
-
阅读此处了解为什么它通常是一个坏主意的更多信息:gamedev.stackexchange.com/questions/1589/… 您现在总是需要能够保证恒定的帧速率,但这并不总是可能的
标签: c# unity3d game-engine unityscript