Ejemplo n.º 1
0
        private void OnCollisionEnter2D(Collision2D other)
        {
            if (other.gameObject.CompareTag("Fire"))
            {
                OnFireTouched?.Invoke();
            }

            if (other.gameObject.tag.Contains("Obstacle"))
            {
                Destroy(other.gameObject);
                OnObstacleHit?.Invoke();
            }

            if (other.gameObject.CompareTag("Ground"))
            {
                OnJumpLanding?.Invoke();
            }

            if (other.gameObject.tag.Contains("PowerUp"))
            {
                Destroy(other.gameObject);
                MainScript.Instance.obstaclesInScene.RemoveAt(0);
                if (other.gameObject.tag.Contains("Clock"))
                {
                    OnClockPowerUpCollected?.Invoke();
                }
                else if (other.gameObject.tag.Contains("Shield"))
                {
                    OnShieldPowerUpCollected?.Invoke();
                }
            }
        }
Ejemplo n.º 2
0
    void UpdateJumping()
    {
        switch (jumpState)
        {
        case JumpState.JumpReady:
            if (input.SpaceHeld && grounded.isGrounded && !grounded.standingOnHeldObject)
            {
                Jump();
            }
            return;

        case JumpState.Jumping:
            timeSpentJumping += Time.fixedDeltaTime;
            underMinJumpTime  = timeSpentJumping < minJumpTime;
            if (underMinJumpTime)
            {
                return;
            }
            else if (grounded.isGrounded)
            {
                jumpCooldownRemaining = jumpCooldown;
                OnJumpLanding?.Invoke();
                jumpState = JumpState.JumpOnCooldown;
            }

            return;

        case JumpState.JumpOnCooldown:
            jumpCooldownRemaining = Mathf.Max(jumpCooldownRemaining - Time.fixedDeltaTime, 0.0f);
            if (jumpCooldownRemaining == 0.0f)
            {
                jumpState = JumpState.JumpReady;
            }
            return;
        }
    }