using UnityEngine;
using System.Collections;

public class Projectile : 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 () {
	
	}
	
	// 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);
        damage += multiplierDmgMax * (multiplierDmg/100);
        StartCoroutine(LifeCounter());
    }

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

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

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