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.8f;
    public GameObject dashAttackEffect;
    public float offset;
    public DashEffect dashEffect;
    private void Update()
    {
        if (isDash)
        {
            time += Time.deltaTime;
            Dash();
            if(time >= dashTime)
            {
                DashAttackEffect();
                dashEffect.canHit = false;
                demonic.ChangeState(CharacterState.Fall);
                this.enabled = false;

            }
            if(time >= 1.33f)
            {
                
            }
        }
    }
    void DashAttackEffect()
    {
        rb.velocity = Vector3.zero;
        
    }
    private void Dash()
    {
        if (demonic.bodyTrans.localScale.x < 0)
        {
            rb.velocity = Vector3.right * moveSpeed;
            dashEffect.offset = offset;
        }
        if (demonic.bodyTrans.localScale.x > 0)
        {
            rb.velocity = Vector3.left * moveSpeed;
            dashEffect.offset = -offset;
        }
    }
}
