[DB-RS] Je voudrais mettre un délai sur mon script
Publié : 03 Juin 2018 12:42
Yop, je suis actuellement sur un jeu "shooter2D" et j'ai ajouter récemment ajouter un "Dash" sur mon personnage, or voila, j'ai créer mon script via un tuto sur internet, tout fonctionne mais je voudrait ajouter un délai entre chaque dash du personnage. Je sais que c'est compliquer, c'est pourquoi je vous demande votre aide , voici mon script :
.
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DashMove : MonoBehaviour {
private Rigidbody2D rb;
public float dashSpeed;
private float dashTime;
public float startDashTime;
private int direction;
void Start(){
rb = GetComponent<Rigidbody2D>();
dashTime = startDashTime;
}
void Update(){
if(direction == 0){
if(Input.GetKeyDown(KeyCode.LeftArrow)) {
direction = 1;
} else if (Input.GetKeyDown(KeyCode.RightArrow)) {
direction = 2;
} else if (Input.GetKeyDown(KeyCode.UpArrow)) {
direction = 3;
} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
direction = 4;
}
} else {
if (dashTime <= 0){
direction = 0;
dashTime = startDashTime;
rb.velocity = Vector2.zero;
} else {
dashTime -= Time.deltaTime;
if (direction == 1) {
rb.velocity = Vector2.left * dashSpeed;
} else if (direction == 2){
rb.velocity = Vector2.right * dashSpeed;
} else if (direction == 3){
rb.velocity = Vector2.up * dashSpeed;
} else if (direction == 4){
rb.velocity = Vector2.down * dashSpeed;
}
}
}
}
}