using UnityEngine;
using System.Collections;

public class EnemyProjectile : MonoBehaviour {

    public float multiplierDmgMax = 0f;
    public float multiplierSpeedMax = 0f;

    public float speed = 0f;
    public float damage = 0f;

    public float lifeLength = 0f;

    // Use this for initialization
    void Start()
    {
        StartCoroutine(LifeCounter());
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        transform.Translate(Vector3.forward * speed * Time.deltaTime);
    }

    public void Construct(float multiplierDmg, float multiplierSpeed)
    {
        speed += multiplierSpeedMax * (multiplierSpeed / 100);
        Debug.Log(speed);
        damage += multiplierDmgMax * (multiplierDmg / 100);
    }

    public void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            other.GetComponent<Player>().TakeDamage(damage);
        }
        if (!other.CompareTag("Enemy") && !other.CompareTag("Interactive"))
        {
            Debug.Log("HIT");
            Die();
        }
    }

    IEnumerator LifeCounter()
    {
        yield return new WaitForSeconds(lifeLength);
        Die();
    }

    void Die()
    {
        Destroy(gameObject);
    }
}
