title: shoot to mouse click direction unity3D
body: <p>Im learning unity3D Im creating a simple game where the player needs to shoot the enemies that are falling from the sky. I already made everything but when I try to shoot where the player clicks on screen I get this error NullReferenceException: Object reference not set to an instance of an object. The funny thing is that is shooting the ball towards the click but the game abruptly quits because of the exception. I have this code attached to my player:</p>
  
  <pre><code>if(Input.GetMouseButtonDown(0)){
  
          shootDirection = Input.mousePosition;
          shootDirection.z = 0.0f;
          shootDirection = Camera.main.ScreenToWorldPoint (shootDirection);
          shootDirection = shootDirection - transform.position;
  
          Rigidbody2D bulletInstance = Instantiate(bulletPrefab, transform.position, Quaternion.Euler(new Vector3(0,0,0))) as Rigidbody2D;
          bulletInstance.velocity = new Vector2(shootDirection.x * speed, shootDirection.y * speed);
  </code></pre>
  
  <p>The error is pointing me in the console is this line:</p>
  
  <pre><code>bulletInstance.velocity = new Vector2(shootDirection.x * speed, shootDirection.y * speed);
  </code></pre>
  
  <p>It would be very helpful if someone can point me out where is my error or what's going on.</p>