0

弾丸が発射し続ける 次の方法で弾丸を実装しましたが、ただ上がっているように見えます。何が間違っていましたか?

public class Player1Controls : MonoBehaviour {

 // Update is called once per frame 
 public float speed;
 Rigidbody2D player;
 public float health;
 private int state;
 public Rigidbody2D Bullet;
 public GameObject Gun;
 void Start ()
 {
     player = GetComponent<Rigidbody2D>();
 }
void Update ()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
     Rigidbody2D bullet1 = (Rigidbody2D)Instantiate (Bullet, Gun.transform.position,Quaternion.identity);
 }
 if(Input.GetKey(KeyCode.W))
 {
     //transform.Translate(Vector2.up * speed);
     player.velocity =(Vector2.up*speed);
     state = 1;
 }

public class MoveBullet : MonoBehaviour {

 public float speed;
 // Update is called once per frame
 void Update () {
     Vector3 pos = transform.position;
     Vector3 vel = new Vector3(0, speed * Time.deltaTime, 0);
     pos = pos + transform.rotation * vel;
     transform.position = pos;
 }
4

2 に答える 2

1

vector3 で x と z を使用します。ユニティでは、y は上向きで、z は「前方」(シーンに向かって) です。

于 2016-04-18T15:53:07.063 に答える