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

public class FloatEffect : MonoBehaviour
{
    public bool isEnemy = false;
    private GameObject effect;
    private ParticleSystem ps;

    private void Start()
    {
        //Invoke("disappear", 0.2f);
        effect = transform.GetChild(1).gameObject;
        ps = effect.GetComponent<ParticleSystem>();
    }

    private void disappear()
    {
        GetComponent<Collider>().enabled = false;
    }

    private void OnTriggerEnter(Collider other)
    {
        if (!isEnemy && other.gameObject.layer == 8)
        {
            GameObject ga = other.transform.parent.parent.parent.gameObject;
            ga.GetComponent<Enemy>().FloatStateOn();
        }
        else if(isEnemy && other.gameObject.layer == 7)
        {
            GameObject ga = other.transform.parent.parent.parent.gameObject;
            ga.GetComponent<Demonic>().FloatStateOn();
        }
        else if(isEnemy && other.gameObject.layer == 6)
        {
            GameObject ga = other.transform.parent.parent.parent.gameObject;
            ga.GetComponent<PlayerController>().lostMp = 0;
            ga.GetComponent<PlayerController>().soulCollector.enabled = false;
            ga.GetComponent<PlayerController>().FloatStateOn();
        }
    }

    private void Update()
    {
        if (ps.isStopped)
        {
            gameObject.SetActive(false);
        }
    }
}
