Exemplo n.º 1
0
 private void SpawnCollect()
 {
     foreach (var spawnObj in currentSpawns)
     {
         var spawn = spawnObj.GetComponent <ItemSpawner>();
         if (spawn.CollectItem(this))
         {
             audioPlayer.PlaySound("Bump");
         }
     }
 }
Exemplo n.º 2
0
    public void Move(float move)
    {
        if (dashRequested && !isDashing)
        {
            audioPlayer.PlaySound("Dash");
            isDashing        = true;
            currentDashTimer = DashDuration;
        }

        if (isDashing)
        {
            currentDashTimer -= Time.deltaTime;
            if (currentDashTimer <= 0)
            {
                isDashing = false;
            }
            else
            {
                Vector3 targetVelocity = new Vector2(DashSpeed * (m_FacingRight ? 10f : -10f), 0);
                m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);
            }
        }

        //only control the player if grounded or airControl is turned on
        if ((m_Grounded || m_AirControl) && !isDashing)
        {
            // Move the character by finding the target velocity
            Vector3 targetVelocity = new Vector2(move * 10f * m_RunSpeed, m_Rigidbody2D.velocity.y);
            // And then smoothing it out and applying it to the character
            m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);
            //TODO add dash canceling logic


            // If the input is moving the player right and the player is facing left...
            if (move > 0 && !m_FacingRight)
            {
                // ... flip the player.
                Flip();
            }
            // Otherwise if the input is moving the player left and the player is facing right...
            else if (move < 0 && m_FacingRight)
            {
                // ... flip the player.
                Flip();
            }
        }
        // If the player should jump...
        if (m_Grounded && jumpRequested)
        {
            audioPlayer.PlaySound("Jump");
            // Add a vertical force to the player.
            m_Grounded = false;
            //Dash Cancel
            isDashing = false;
            m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, 0);
            m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
        }

        if (doubleJumpRequested)
        {
            audioPlayer.PlaySound("Jump");
            animator.SetTrigger("DoubleJump");
            //Dash Cancel
            m_Grounded             = false;
            isDashing              = false;
            m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, 0);
            m_Rigidbody2D.AddForce(new Vector2(0f, m_DoubleJumpForce));
        }

        if (isShielded)
        {
            currentShieldTimer -= Time.deltaTime;
            if (currentShieldTimer <= 0)
            {
                isShielded = false;
            }
        }

        shieldRenderer.enabled = isShielded;
        LifeText.text          = "Life : " + currentLife;

        jumpRequested       = false;
        dashRequested       = false;
        doubleJumpRequested = false;
    }