using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{

    public bool playerCollided;
    PlayerControllerScript playerScript;
    public Vector3 steering;
    // Use this for initialization
    void Start()
    {
        playerCollided = false;
        playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerControllerScript>();
        gameObject.AddComponent<Rigidbody2D>();
        gameObject.GetComponent<Rigidbody2D>().gravityScale = 0;
        gameObject.AddComponent<BoxCollider2D>();
        StartCoroutine(BulletTimer());
    }

    void FixedUpdate()
    {
        transform.position += steering * Time.deltaTime;
    }

    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "Player")
        {
            playerScript.TakeDamage(1);
            Destroy(this.gameObject);
        }

        //Destroy(this.gameObject);
    }

    IEnumerator BulletTimer()
    {
        yield return new WaitForSeconds(3);
        Destroy(this.gameObject);
    }
}


