- Home /
Question by
NiqhtFire · Apr 07, 2020 at 07:36 AM ·
scripting problemscripting beginnerscriptingbasicsdash
My player keeps dashing
i couldn't find the mistake if u can plsplspls help me using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Dash : MonoBehaviour
{
public float dashTime;
private bool dashing;
public float dashSpeed;
public float dashCoolDown;
private float dashTimeLeft;
private float lastDash = -100f;
public Rigidbody2D rb;
private float facingDirection;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
checkDash();
facingDirection = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Dash"))
{
if (Time.time >= lastDash + dashCoolDown)
{
AttemptToDash();
}
}
}
private void AttemptToDash()
{
dashing = true;
dashTimeLeft = dashTime;
lastDash = Time.time;
}
private void checkDash()
{
if (dashing)
{
if(dashTimeLeft > 0)
{
Debug.Log("calisiyor");
rb.velocity = new Vector2(dashSpeed * facingDirection, rb.velocity.y);
}
if(dashTimeLeft < 0)
{
dashing = false;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Can someone explain calling other scripts in C#? 2 Answers
How to add force if spherecast is true and how to set direction of sphere 0 Answers
How can I slow the velocity of my player without it affecting fall speed? 0 Answers
How do I make a photography function? 0 Answers
Running scripts from editor 1 Answer