Ejemplo n.º 1
0
 public void StartJumpButtonPress()
 {
     if (isHUDActive && player.GetCanJump())
     {
         jumpButtonHeld = true;
         playerAudio.PlayChargingSound();
     }
 }
Ejemplo n.º 2
0
    private void DetectJumpButtonPress()
    {
        // detect jump button press for spaceKey
        if (canControl && canJump)
        {
            if (Input.GetKeyDown(KeyCode.Space) ||
                (Input.GetKey(KeyCode.Space) && currentChargeTime > 0f))
            {
                currentChargeTime += Time.deltaTime;
                if (currentChargeTime > 0.15f && currentChargeTime < maxChargeTime)
                {
                    playerAudio.PlayChargingSound();
                    chargeBar.SetActive(true);
                    chargeBar.transform.localScale = new Vector3(chargeBar.transform.localScale.x,
                                                                 Mathf.Lerp(3f, 15f, currentChargeTime / maxChargeTime),
                                                                 chargeBar.transform.lossyScale.x);
                }
                else if (currentChargeTime >= maxChargeTime)
                {
                    playerAudio.PlayMaxedChargingSound();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Space) && currentChargeTime > 0f)
            {
                LeavePlanet(currentChargeTime);
                currentChargeTime = 0;
                chargeBar.SetActive(false);
                playerAudio.StopChargingSound();
            }
        }

        // detect jumpButton press with touch
        if (canControl && canJump && Input.touchCount > 0 &&
            GameManager.instance.IsTouchPositionValid(Input.touches[0].position))
        {
            Touch touch = Input.touches[0];

            if (touch.phase == TouchPhase.Began ||
                (touch.phase == TouchPhase.Stationary && currentChargeTime > 0f) ||
                (touch.phase == TouchPhase.Moved && currentChargeTime > 0f))
            {
                currentChargeTime += Time.deltaTime;
                if (currentChargeTime > 0.15f && currentChargeTime < maxChargeTime)
                {
                    playerAudio.PlayChargingSound();
                    chargeBar.SetActive(true);
                    chargeBar.transform.localScale = new Vector3(chargeBar.transform.localScale.x,
                                                                 Mathf.Lerp(3f, 15f, currentChargeTime / maxChargeTime),
                                                                 chargeBar.transform.lossyScale.x);
                }
                else if (currentChargeTime >= maxChargeTime)
                {
                    playerAudio.PlayMaxedChargingSound();
                }
            }
            else if (Input.touches[0].phase == TouchPhase.Ended && currentChargeTime > 0f)
            {
                LeavePlanet(currentChargeTime);
                currentChargeTime = 0;
                chargeBar.SetActive(false);
                playerAudio.StopChargingSound();
            }
        }
    }