using UnityEngine;
using System.Collections;

public class homingBullet : MonoBehaviour {

    public Transform target;
    public float speed;
    Transform trans;
    private float timer;
    public float despawn;

	// Use this for initialization
	void Start () {
        if (target == null)
        {
            target = GameObject.FindWithTag("Player").transform;
        }
        trans = GetComponent<Transform>();
        timer = Time.time;
	}
	
	// Update is called once per frame
	void Update () {
        trans.LookAt(target);
        trans.Translate(Vector3.forward * speed * Time.deltaTime);
        if (Time.time - timer >= despawn)
        {
            Destroy(gameObject);
        }
	}
}
