title: How to make Bullet initiate from the direction the player is in
body: <p>I am making 2D game in Unity.</p>
  
  <p>In this I wanted to add a bullet with a limited number of shots.</p>
  
  <p>The bullet fires in the direction in which the player is but always initiate from the right side even if the player is facing left side. And I have limited the bullet count to 3.</p>
  
  <p>How do I put delay in between the occurrence of the bullets?</p>
  
  <p>1st Script (Bullet)</p>
  
  <pre><code>public class Bullet : MonoBehaviour {
  
      private Player player;
      public float speed = 1f;
      public int abc = 2;
  
      // Use this for initialization
      void Start () {
          player = GameObject.Find ("Player").GetComponent&lt;Player&gt; ();
          if (player.aa.x == transform.localScale.x)
              abc = 1;
      }
  
      // Update is called once per frame
      public void Update () {
          if (abc == 1)
              rigidbody2D.velocity = new Vector3 (transform.localScale.x, 0, 1) * speed;
          else
              rigidbody2D.velocity = new Vector3 (transform.localScale.x, 0, 1) * speed;
      }
  }
  </code></pre>
  
  <p>2nd Script (Player)</p>
  
  <pre><code>public class Player : MonoBehaviour {
  
      public float speed = 10f;
      public Vector2 maxVelocity = new Vector2(3, 5);
      public bool standing;
      public float jetSpeed = 15f;
      public float airSpeedMultiplier = .3f;
      public AudioClip leftFootSound;
      public AudioClip rightFootSound;
      public AudioClip thudSound;
      public AudioClip rocketSound;
      public Vector3 aa = new Vector3(1,1,1);
  
      private Animator animator;
      private PlayerController controller;
  
      void Start(){
          controller = GetComponent&lt;PlayerController&gt; ();
          animator = GetComponent&lt;Animator&gt; ();
      }
  
      void PlayLeftFootSound(){
          if (leftFootSound)
              AudioSource.PlayClipAtPoint (leftFootSound, transform.position);
      }
  
      void PlayRightFootSound(){
          if (rightFootSound)
              AudioSource.PlayClipAtPoint (rightFootSound, transform.position);
      }
  
      void PlayRocketSound(){
          if (!rocketSound || GameObject.Find ("RocketSound"))
              return;
  
          GameObject go = new GameObject ("RocketSound");
          AudioSource aSrc = go.AddComponent&lt;AudioSource&gt; ();
          aSrc.clip = rocketSound;
          aSrc.volume = 0.7f;
          aSrc.Play ();
  
          Destroy (go, rocketSound.length);
      }
  
      void OnCollisionEnter2D(Collision2D target){
          if (!standing) {
              var absVelX = Mathf.Abs(rigidbody2D.velocity.x);
              var absVelY = Mathf.Abs(rigidbody2D.velocity.y);
  
              if(absVelX &lt;= .1f || absVelY &lt;= .1f){
                  if(thudSound)
                      AudioSource.PlayClipAtPoint(thudSound, transform.position);
              }
          }
      }
  
      // Update is called once per frame
      void Update () {
          var forceX = 0f;
          var forceY = 0f;
  
          var absVelX = Mathf.Abs (rigidbody2D.velocity.x);
          var absVelY = Mathf.Abs (rigidbody2D.velocity.y);
  
          if (absVelY &lt; .2f)
              standing = true;
          else
              standing = false;
  
          if (controller.moving.x != 0) {
              if (absVelX &lt; maxVelocity.x) {
  
                  forceX = standing ? speed * controller.moving.x : (speed * controller.moving.x * airSpeedMultiplier);
  
                  aa = transform.localScale = new Vector3 (forceX &gt; 0 ? 1 : -1, 1, 1);
  
              }
  
              animator.SetInteger ("AnimState", 1);
  
          } else {
              animator.SetInteger ("AnimState", 0);
          }
  
          if (controller.moving.y &gt; 0) {
              PlayRocketSound();
                          if (absVelY &lt; maxVelocity.y)
                                  forceY = jetSpeed * controller.moving.y;
  
                          animator.SetInteger ("AnimState", 2);
                  } else if (absVelY &gt; 0) {
              animator.SetInteger("AnimState", 3);
                  }
  
          rigidbody2D.AddForce (new Vector2 (forceX, forceY));
      }
  }
  </code></pre>
  
  <p>3rd Script (PlayerController)</p>
  
  <pre><code>public class PlayerController : MonoBehaviour {
  
      public Vector2 moving = new Vector2();
      public int Bulletlimit = 0;
      public int MaxBulletlimit = 3;
      public float bulletDelay = 3f;
      public bool Gun;
  
      public Bullet bullet;
      // Use this for initialization
      void Start () {}
  
      // Update is called once per frame
      void Update () {
  
          moving.x = moving.y = 0;
  
          if (Input.GetKey ("right")) {
              moving.x = 1;
          } else if (Input.GetKey ("left")) {
              moving.x = -1;
          }
  
          if (Input.GetKey ("up")) {
              moving.y = 1;
          } else if (Input.GetKey ("down")) {
              moving.y = -1;
          }
  
          if (Input.GetKey ("s")) {
              if(Gun){
                  if(Bulletlimit &lt; MaxBulletlimit)
                  {
                      Bullet clone = Instantiate (bullet, transform.position, Quaternion.identity) as Bullet;
                      Bulletlimit = Bulletlimit + 1;
                  }
              }
          }   
      }
  
      public void BulletCount() {
          Bulletlimit = Bulletlimit - 1;
      }
  }
  </code></pre>