2017-04-20 41 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

对不起,我太初学者了解你的建议。如果你编写代码将会很感激。谢谢 –