I don't know why. I didn't add anything new to the 2d platformer user controller script (just the default lines of code is there that comes with the character you get from the asset store (the robot guy). I will include both scripts, that script and my dash script. No matter what key on the keyboard I attach the other dashing directions to, it still doesn't work. I am not sure why only dashing up works. Dash: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; //makes character dash public class DashMove : MonoBehaviour { private Rigidbody2D rb; public float dashSpeed; private float dashTime; //how long the dash lasts public float startDashTime; //decrease the value of dashTime in-game, so when dashTime is equal to 0 we know the dash is over private int direction; void Start() { rb = GetComponent<Rigidbody2D>(); dashTime = startDashTime; } private void Update() { if (direction == 0) { //if it is, it means our player isn't dashing if (Input.GetKeyDown(KeyCode.Z)) direction = 1; } else if (Input.GetKeyDown(KeyCode.X)) { direction = 2; } else if (Input.GetKeyDown(KeyCode.C)) { direction = 3; } else if (Input.GetKeyDown(KeyCode.V)) { direction = 4; } else { if (dashTime <= 0)//dashTime variable to decrease or the dash will never stop { direction = 0; dashTime = startDashTime; rb.velocity = Vector2.zero; //or else the player will continue to dash foward } else { dashTime -= Time.deltaTime; if (direction == 1) { //dashes up rb.velocity = Vector2.up * dashSpeed; } else if (direction == 2) { rb.velocity = Vector2.right * dashSpeed; } else if (direction == 3) { rb.velocity = Vector2.left * dashSpeed; } else if (direction == 4) { rb.velocity = Vector2.down * dashSpeed; } } } } } Character controller: Code (CSharp): using System; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; namespace UnityStandardAssets._2D { [RequireComponent(typeof (PlatformerCharacter2D))] public class Platformer2DUserControl : MonoBehaviour { private PlatformerCharacter2D m_Character; private bool m_Jump; private void Awake() { m_Character = GetComponent<PlatformerCharacter2D>(); } private void Update() { if (!m_Jump) { // Read the jump input in Update so button presses aren't missed. m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } } private void FixedUpdate() { // Read the inputs. bool crouch = Input.GetKey(KeyCode.LeftControl); float h = CrossPlatformInputManager.GetAxis("Horizontal"); // Pass all parameters to the character control script. m_Character.Move(h, crouch, m_Jump); m_Jump = false; } } }
Looks like you're messed up with {}: Code (CSharp): if (direction == 0) { //if it is, it means our player isn't dashing if (Input.GetKeyDown(KeyCode.Z)) direction = 1; } else if (Input.GetKeyDown(KeyCode.X)) { direction = 2; } In this code, the direction will become 2 only if player is already dashing (i.e. direction != 0). To fix that, you need to move all the input checks into first control block, where the Z key is checked. Code (CSharp): if (direction == 0) { //if it is, it means our player isn't dashing if (Input.GetKeyDown(KeyCode.Z)) direction = 1; else if (Input.GetKeyDown(KeyCode.X)) direction = 2; // etc... } Also your code will be much cleaner if you will use vectors for directions instead of integers, like this: Code (CSharp): direction = Vector3.up; rb.velocity = direction * dashSpeed;