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

public class Spirits_Dash : MonoBehaviour
{
    public float moveSpeed;
    public Rigidbody rb;
    public Demonic demonic;
    public bool isDash;
    [HideInInspector]
    public float time;
    public float dashTime = 0.5f;
    public GameObject dashAttackEffect;
    public float offset;
    public DashEffect dashEffect;
    public Vector3 dir;
    public float force;
    private void Update()
    {
        if (isDash)
        {
            time += Time.deltaTime;
            Dash();
            if(time >= dashTime)
            {
                DashAttackEffect();
                
            }
            if(time >= 1.34f)
            {
                this.enabled = false;
            }
        }
    }
    void DashAttackEffect()
    {
        rb.velocity = Vector3.zero;
        dashEffect.canHit = true;
    }
    private void Dash()
    {
        if (demonic.bodyTrans.localScale.x < 0)
        {
            rb.velocity = Vector3.right * moveSpeed;
            dashEffect.offset = offset;
            dashEffect.force = new Vector3(dir.x *force,dir.y,0);
        }
        if (demonic.bodyTrans.localScale.x > 0)
        {
            rb.velocity = Vector3.left * moveSpeed;
            dashEffect.offset = -offset;
            dashEffect.force = new Vector3(dir.x * -force, dir.y, 0);
        }
    }
}
