我需要帮助来修复以下代码,以便能够触发火灾时触发火灾1按钮当我在我的手机上使用unity遥控器时它不起作用
脚步
-
将PlayerShoot脚本绑定到GameObject
-
点击场景中的按钮,转到检查员 . 并添加一个OnClick事件,拖动包含脚本的游戏对象,然后选择Fire()函数 .
-
使用移动设备上的Unity远程应用程序,其中火按钮不起作用
我使用的代码...如下:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerShoot : MonoBehaviour {
public GameObject Ammo; // the shot
GameObject FiredShot;
public AudioClip bcgMusic;
public List<GameObject> ShotsOnAir;
//public AudioClip sound1; // Use this for initialization
void Start (){
ShotsOnAir = new List<GameObject>();
}
//void Update (){
// Fire ();
//}
public void Fire(){
if (Input.GetButtonDown ("Fire1")){
FiredShot = (GameObject)Instantiate(Ammo,transform.position,transform.rotation);
ShotsOnAir.Add(FiredShot);
AudioSource.PlayClipAtPoint (bcgMusic, transform.position);
}
if(ShotsOnAir != null){
int i=0;
foreach (GameObject GB in ShotsOnAir){
ShotsOnAir[i].transform.position += ShotsOnAir[i].transform.forward * 200 * Time.deltaTime;
i++;
}
}
}
}
2 回答
Input.GetButton()在移动设备上不起作用
您需要使用Input.touches / Input.GetTouch()