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

public class LifeUp : MonoBehaviour {

    public int value = 1;
    bool Targeting = false;
    float targetingTimer = 0f;

    private void Start()
    {
        transform.localScale = Vector3.one * 0.05f * value;
    }

    void OnTriggerEnter(Collider col)
    {
        if (!Targeting)
        {
            if (col.tag == "Particle")
            {
                if (col.gameObject == ParticleController.player.gameObject)
                {
                    Targeting = true;
                    targetingTimer = 0;
                }
                else
                {
                    ParticleController.player.intensity += value/2;
                    ParticleController.player.Hitch();
                    Destroy(gameObject);
                }
            }
        }
    }

    private void Update()
    {
        if (Targeting)
        {
            float dist = Vector3.Distance(transform.position, ParticleController.player.transform.position);
            transform.position = transform.position * (0.9f - 0.9f * targetingTimer) + ParticleController.player.transform.position * (0.1f + 0.9f * targetingTimer);
            if (dist < 0.5f)
            {
                ParticleController.player.intensity += 1;
                ParticleController.player.Hitch();
                Destroy(gameObject);
            }
            if (targetingTimer < 1f)
            {
                targetingTimer += Time.deltaTime / 2f;
            }
        }
    }
}

