2015-04-20 74 views
0

我在Unity 3D 制作游戏和使用统一的点击转换器将其转换在安卓apk文件团结Android的游戏控制器

的游戏在Android手机 开放,但玩家是不动

播放器脚本:

using UnityEngine; 
using System.Collections; 

public class PlayerController : MonoBehaviour { 

    public Vector2 moving = new Vector2(); 
    public int Bulletlimit = 0; 
    public int MaxBulletlimit = 3; 
    public bool Gun; 
    private float lastShotTime ; 
    public float fireDelay = 0.2f; 
    public Transform BulletDirection; 

    public Bullet bullet; 

    // Use this for initialization 
    void Start() { 
     lastShotTime = Time.time; 
    } 

    // Update is called once per frame 
    void Update() { 


     moving.x = moving.y = 0; 

     if (Input.GetKey ("right")) { 
      moving.x = 1; 
     } else if (Input.GetKey ("left")) { 
      moving.x = -1; 
     } 

     if (Input.GetKey ("up")) { 
      moving.y = 1; 
     } else if (Input.GetKey ("down")) { 
      moving.y = -1; 
     } 


     if (Input.GetKey ("s")) { 

      if(Gun){ 
      if(Bulletlimit < MaxBulletlimit) 
      { 

        if(Time.time > lastShotTime + fireDelay) 
        { 
         Bullet clone = Instantiate (bullet, BulletDirection.position, Quaternion.identity) as Bullet; 
        Bulletlimit = Bulletlimit + 1; 
         lastShotTime = Time.time; 
        } 
       } 
      } 
    } 

    } 

    public void BulletCount() 
    { 
     Bulletlimit = Bulletlimit - 1; 
    }   
} 

如何使他在触摸屏移动

+0

给我一个提示或其他东西请 –

回答

0

您的代码为b按键击 - 这(可能)不会适用于您的触摸屏。

有几种方法可以做到这一点,对于这么简单的事情,我可能会尝试添加一个画布和一些按钮来充当控件。

从那里你可以使用OnMouseDown()/ OnMouseUp()/ OnClick()方法(这也转换为触摸屏),而不是击键。

如何从那里选择代码,但在这种情况下,我可能会使用按钮来打开/关闭移动布尔,并在Update()方法中检查/应用它们。

如果你不确定如何使用新的统一UI试试这个...

https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-canvas

如果你正在运行的统一的新版本(目前5.1我认为),我的编辑看起来与教程不同,并且由于某些原因不会保持默认状态。如果某些选项似乎丢失,只需将编辑器/检查器视图设置为默认值即可。

有更复杂的东西,你可以实际触摸输入做,但我不认为你需要担心它在这种特殊情况下。

希望这有助于:)