コード例 #1
0
ファイル: Player.cs プロジェクト: xdaisy/platformer_2d
 /// <summary>
 /// What happens when player gets hit by an enemy
 /// </summary>
 public void Hit()
 {
     if (invincibilityCoolDown <= 0f && poweredUp)
     {
         AudioManager.Instance.PlaySFX(Constants.POWER_DOWN_SFX);
         poweredUp             = false;
         invincibilityCoolDown = invincibilityFrame;
         StartCoroutine(playPowerDownAnim());
     }
     else if (invincibilityCoolDown <= 0f)
     {
         // get camera to stop following player
         CustomCamera cam = GameObject.FindObjectOfType <CustomCamera>();
         cam.StopFollowingPlayer();
         Destroy(myRigidBody);
         isAlive = false;
     }
 }
コード例 #2
0
ファイル: Player.cs プロジェクト: xdaisy/platformer_2d
    /// <summary>
    /// Move the player
    /// </summary>
    private void handleMovement()
    {
        if (!isAlive && deathWaitTime < Constants.DEATH_WAIT_TIME)
        {
            // died so move player to left side of the screen
            deathWaitTime          += Time.deltaTime;
            this.transform.position = this.transform.position + (Vector3.left * 0.25f);
        }
        else if (!EndStage.Instance.HasStageFinished())
        {
            // if game is still continuing
            if (canMove)
            {
                float moveX = Input.GetAxisRaw("Horizontal");

                myRigidBody.velocity = new Vector2(moveX * MoveSpeed, myRigidBody.velocity.y);
            }
            else
            {
                // freeze the player in the current position they are in
                myRigidBody.velocity = Vector2.zero;
            }
        }
        else
        {
            // stage has been finished
            if (isGrounded())
            {
                // if the player is grounded
                anim.SetBool("isMoving", false);
                anim.SetBool("isJumping", false);

                // play animation
                CustomCamera cam = GameObject.FindObjectOfType <CustomCamera>();
                EndStage.Instance.PlayEndAnimation(poweredUp);
                cam.StopFollowingPlayer();
                Destroy(this.gameObject);
            }
        }
    }