2017-04-20 39 views
1

如果玩家不移動並且只是站在預製子彈中就是正常運動(圖A)。 我的預製件在玩家跑步或移動時表現出不良行爲(圖片B)。怪異行爲實例子彈預製

Please Check the Picture

這是我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); 
} 
} 
+0

你應該發送bullet腳本。子彈如何移動? –

+0

是否將此腳本附加到您的Player對象? – Hristo

+0

@MustafaErdemKöşkoke我只是這樣做。 –

回答

0

我認爲這僅僅是物理。你假設子彈的初始速度爲零,但事實並非如此。這是射手的當前速度。嘗試在子彈對象中設置初始速度並將其添加到speed

+0

對不起,我太初學者瞭解你的建議。如果你編寫代碼將會很感激。謝謝 –