using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dash : MonoBehaviour
{
public Rigidbody2D rb;
public float dashSpeed;
private float dashTime;
public float startDashTime;
private int direction;
private bool isDashing;
[SerializeField]
private GameObject dashEffect;
// Start is called before the first frame update
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
dashTime = startDashTime;
}
// Update is called once per frame
void Update()
{
if (direction == 0)
{
if (Input.GetKeyDown(KeyCode.R ))
{
Instantiate(dashEffect, transform.position, Quaternion.identity);
direction = 1;
isDashing = true;
}
else if (Input.GetKeyDown(KeyCode.T))
{
Instantiate(dashEffect, transform.position, Quaternion.identity);
direction = 2;
isDashing = true;
}
}
else
{
if (dashTime <= 0)
{
direction = 0;
dashTime = startDashTime;
rb.velocity = Vector2.zero;
isDashing = false;
}
else
{
dashTime -= Time.deltaTime;
if (direction == 1)
{
transform.localScale = new Vector3(-1, 1, 1);
rb.velocity = Vector2.left * dashSpeed;
}
else if (direction == 2)
{
transform.localScale = new Vector3(1, 1, 1);
rb.velocity = Vector2.right * dashSpeed;
}
}
}
}
}