title: How to make an enemy shoot the player in unity 2d
body: <p>I'm making a game in Unity and so far the enemy can follow the player and can point the gun at the player. The only thing I need to do now is make the enemy shoot at the player. How do I go about doing this? Here is my Enemy Class so far:</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Enemy : MonoBehaviour
  {
  
      public GameObject player;
      public GameObject gun;
  
      void Update()
      {
          Vector3 difference = player.transform.position - gun.transform.position;
          float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
          gun.transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotationZ);
  
      }
  }
  </code></pre>