Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dash Porblème

Discussion in 'Editor & General Support' started by Leandre5, May 2, 2020.

  1. Leandre5

    Leandre5

    Joined:
    Nov 1, 2017
    Posts:
    42
    Hello, I explain you my problem, I would like to make a dash, I've watched several videos but I can't find a solution for my code (I dash when the time is not less than 0).

    Code (CSharp):
    1. void Update()
    2.     {
    3.         movement.x = Input.GetAxisRaw("Horizontal");
    4.         movement.y = Input.GetAxisRaw("Vertical");
    5.         LastDirection();
    6.            
    7.        
    8.         if(Input.GetKeyDown(KeyCode.Space)){
    9.             if(dashTime < 0){
    10.                 Dash();
    11.                 dashTime = Timetodash;
    12.             }
    13.         }
    14.         dashTime -= Time.deltaTime;
    15.        
    16.     }
    Code (CSharp):
    1. void LastDirection()
    2.     {
    3.         if(Input.GetKeyDown(KeyCode.Z)){
    4.             direction = 1;
    5.         }else if(Input.GetKeyDown(KeyCode.Q)){
    6.             direction = 2;
    7.         }else if(Input.GetKeyDown(KeyCode.S)){
    8.             direction = 3;
    9.         }else if(Input.GetKeyDown(KeyCode.D)){
    10.             direction = 4;
    11.         }
    12.     }
    Code (CSharp):
    1. void Dash()
    2.     {
    3.         if(direction == 1){
    4.             transform.position += new Vector3(5,0,0);
    5.         }else if(direction == 2){
    6.            transform.position += new Vector3(0,5,0);
    7.         }else if(direction == 3){
    8.            transform.position += new Vector3(-5,0,0);
    9.         }else if(direction == 4){
    10.            transform.position += new Vector3(0,-5,0);
    11.         }
    12.     }
     
  2. Leandre5

    Leandre5

    Joined:
    Nov 1, 2017
    Posts:
    42
    sorry i'm in the wrong forum