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

public class Absorber : MonoBehaviour {

    AudioSource AudioS;
    AudioClip aclip;

    private void Start()
    {
        aclip = Resources.Load("absorb") as AudioClip;
        AudioS = gameObject.AddComponent<AudioSource>();
        AudioS.spatialBlend = 0.5f;
        AudioS.loop = false;
        AudioS.playOnAwake = false;
        AudioS.clip = aclip;
    }

    private void OnCollisionEnter(Collision col)
    {
        if (col.collider.tag == "Particle")
        {
            
            ParticleController pc = col.gameObject.GetComponent<ParticleController>();
            if (pc == ParticleController.player)
            {
                Debug.DrawLine(col.contacts[0].point, col.contacts[0].point - col.contacts[0].normal, Color.blue, 5f);
                Debug.DrawLine(col.contacts[0].point, col.contacts[0].point + pc.Direction, Color.green, 5f);
                pc.Direction = Vector3.Reflect(pc.Direction, -col.contacts[0].normal);

                Debug.DrawLine(col.contacts[0].point, col.contacts[0].point + pc.Direction, Color.red, 5f);
            }
            else
            {
                ParticleController.player.subParticles.Remove(pc);
                Destroy(pc.gameObject);
            }

            AudioS.Stop();
            AudioS.Play();
        }
    }
}
