// Start is called before the first frame update void Start() { playerCanMove = true; currentState = playerState.onGround; currentDashDirection = dashDirection.none; playerBody = GetComponent <Rigidbody2D>(); recentWallCollision = GetComponent <GameObject>(); }
// Update is called once per frame void Update() { //if no key is pressed, revert gravity to normal if (!Input.anyKey) { playerBody.gravityScale = 1f; } if (playerCanMove) { if (((Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift)) || (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift)) || (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift)) || (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.LeftShift))) && (currentState != playerState.dashing)) { if (Input.GetKey(KeyCode.A)) { currentDashDirection = dashDirection.left; } else if (Input.GetKey(KeyCode.D)) { currentDashDirection = dashDirection.right; } else if (Input.GetKey(KeyCode.W)) { currentDashDirection = dashDirection.up; } else if (Input.GetKey(KeyCode.S)) { currentDashDirection = dashDirection.down; } Dash(currentDashDirection); } else { if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D)) { bool left = Input.GetKey(KeyCode.A); MoveHorizontal(left); } if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D)) { StopHorizontal(); } if (Input.GetKey(KeyCode.Space)) { Jump(); } if (Input.GetKeyUp(KeyCode.Space)) { if (playerBody.velocity.y > 0) { StopVertical(); } } } } }
void Dash(dashDirection direction) { currentState = playerState.dashing; if (direction == dashDirection.left) { DashLeft(); } else if (direction == dashDirection.right) { DashRight(); } else if (direction == dashDirection.up) { DashUp(); } else if (direction == dashDirection.down) { DashDown(); } StartCoroutine(DashWait()); }