mani
❔ PlayerMovement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DashBuff : MonoBehaviour
{
[SerializeField] private playerMovement; // Reference playerMovement script??
private bool canDash = true;
private bool isDashing;
private float dashingPower = 24f;
private float dashingTime = 0.2f;
private float dashingCooldown = 1f;
[SerializeField] private TrailRenderer tr;
private IEnumerator Dash()
{
canDash = false;
isDashing = true;
float originalGravity = rb.gravityScale;
rb.gravityScale = 0f;
rb.velocity = new Vector2(transform.localScale.x * dashingPower, 0f);
tr.emitting = true;
yield return new WaitForSeconds(dashingTime);
tr.emitting = false;
rb.gravityScale = originalGravity;
isDashing = false;
yield return new WaitForSeconds(dashingCooldown);
canDash = true;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)
{
StartCoroutine(DashBuff());
}
}
}
16 replies