1
如果玩家不移動並且只是站在預製子彈中就是正常運動(圖A)。 我的預製件在玩家跑步或移動時表現出不良行爲(圖片B)。怪異行爲實例子彈預製
這是我firePos腳本:
public class FirePos : MonoBehaviour {
public bool _facingRight;
public GameObject bulletRight, bulletLeft;
bool canShootFire;
// Use this for initialization
void Start() {
canShootFire = true;
_facingRight = GameObject.Find ("Player").GetComponent<PlayerManager>();
}
// Update is called once per frame
void Update() {
if(Input.GetKeyDown(KeyCode.K) && canShootFire && GameObject.Find("Player").GetComponent<PlayerManager>().facingRight){
canShootFire = false;
Instantiate (bulletRight, transform.position, transform.rotation);
StartCoroutine ("Firing");
}
if(Input.GetKeyDown(KeyCode.K) && canShootFire && !GameObject.Find("Player").GetComponent<PlayerManager>().facingRight){
canShootFire = false;
Instantiate (bulletLeft, transform.position, transform.rotation);
StartCoroutine ("Firing");
}
}
IEnumerator Firing(){
yield return new WaitForSeconds (.5f);
canShootFire = true;
}
}
這對子彈運動
public class bulletRight : MonoBehaviour {
public float speed;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
transform.Translate (Vector2.right*speed*Time.deltaTime,0);
Destroy (gameObject,1.5f);
}
}
你應該發送bullet腳本。子彈如何移動? –
是否將此腳本附加到您的Player對象? – Hristo
@MustafaErdemKöşkoke我只是這樣做。 –