title: Enemy attack the player?
body: <p>I created an enemy to attack a player, this enemy has a gun. I want when this gun shot, the shot goes to direction of player. I can instantiate but can't change direction bullet to attack my player in his position.</p>
  
  <p>how can I do this ?</p>
  
  <p>I'm trying this.</p>
  
  <pre><code>public class EnemyShotGun : MonoBehaviour {
  
       public GameObject[] gun; //gun attack player
       public GameObject prefabShot; //shot
       public float enemyShotSpeed;
       private float delayAttack; 
       public float timeAttack; 
  
       //player
       private Transform player;
  
       // Use this for initialization
       void Start () {
           player = GameObject.FindGameObjectWithTag("AirPlane").transform;
       }
  
       // Update is called once per frame
       void Update () {
           delayAttack += Time.deltaTime;
           if (delayAttack &gt;= timeAttack){            
               for(int x = 0; x &lt; gun.Length; x++){
                   GameObject shot = Instantiate(prefabShot, gun[x].transform.position, Quaternion.identity) as GameObject;
                   shot.rigidbody2D.AddRelativeForce(new Vector2(0, -500)); 
                   shot.transform.position = player.position; //bullet goes to player position
               }                        
               delayAttack = 0;
           }
  
       }
   }
  </code></pre>