void Update() { grounded = Physics2D.OverlapCircle(groundCheck.position, groundedRadius, whatIsGround); float move = Input.GetAxis("Horizontal"); if (grounded && rigidbody2D.velocity.y <= 0) { currentJumpTime = 0; spaceDownCount = 0; jumpCount = 0; sdupJump = false; } if (Input.GetKeyDown(KeyCode.Space) || ((Input.touchCount > 0) && (Input.GetTouch(0).position.x < Screen.width / 2) && Input.GetTouch(0).phase == TouchPhase.Began)) { spaceDownCount += 1; jumpCount += 1; if (jumpCount == 1 && !grounded) { sdupJump = true; } if (grounded) { audio.PlayOneShot(jumpNoise); rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, initialJumpBoost); currentJumpTime = 0; } else if ((jumpCount == 2 && powerUp.Equals("doubleJump"))) { audio.PlayOneShot(jumpNoise); rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, doubleJumpBoost); } else if (jumpCount == 1) { audio.PlayOneShot(jumpNoise); rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, sdupJumpBoost); } } if (Input.GetKey(KeyCode.Space) || ((Input.touchCount > 0) && Input.GetTouch(0).position.x < Screen.width / 2)) { currentJumpTime += Time.deltaTime; if ((currentJumpTime < maxJumpTime) && sdupJump == false && rigidbody2D.velocity.y > 0 && (spaceDownCount == 1 || spaceDownCount == 0 || (powerUp.Equals("doubleJump") && jumpCount < 2))) { if (spaceDownCount == 0) { spaceDownCount = 1; } rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, rigidbody2D.velocity.y + jumpIncrement); } else if (grounded) { rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, initialJumpBoost); currentJumpTime = 0; jumpCount = 1; } } if (jumpCount > 0) { currentVelocity = (maxSpeed - speedDecrease); } else { currentVelocity = maxSpeed; } if (!forcedRunner) { currentVelocity = currentVelocity * move; } rigidbody2D.velocity = new Vector2(currentVelocity, rigidbody2D.velocity.y); if ((Input.GetKey(KeyCode.X) || ((Input.touchCount > 0) && (Input.GetTouch(0).position.x >= Screen.width / 2))) && ((powerUp != "None") && (powerUp != "doubleJump"))) { //use shield if (powerUp == "shield") { Shield shield = activatable.GetComponent <Shield>(); shield.Activate(); } if (powerUp == "boost") { Boost boost = activatable.GetComponent <Boost>(); boost.Activate(); } } distanceTraveled = transform.localPosition.x; // Debug.Log ("Player.cs distancetravleled " + distanceTraveled); }