예제 #1
0
    // checking if Mario collides with an enemy
    private void OnCollisionEnter2D(Collision2D other)
    {
        GameObject enemy = other.gameObject;

        // if Mario jumped over the enemy
        // Debug.Log(checkGround.isInGround);
        if ((!checkGround.IsGrounded() || stateManager.starMario) && enemy.CompareTag("Enemy"))
        {
            Animator enemyAnimator = enemy.GetComponent <Animator>();
            GameController.Instance.IncreasePoints(100);

            if (!stateManager.starMario)
            {
                enemyAnimator.SetBool("Dead", true);
            }
            else
            {
                Destroy(enemy);
            }

            stateManager.KillEnemy();
        }
        // if not check if Mario has an extra live to kill him or not
        else if (enemy.CompareTag("Enemy") || enemy.CompareTag("Trap"))
        {
            stateManager.DeadMario(false);
        }
    }
예제 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // if Mario dies, getting down away
        if (transform.position.y < deadPoint)
        {
            marioStateManager.DeadMario(true);
        }

        // else while Mario is alived, the player can play
        else if (!MarioStateManager.marioIsDead && !MarioStateManager.completedLevel)
        {
            // horizontal moving
            float horizontalMove = Input.GetAxis("Horizontal");
            transform.Translate(Vector3.right * horizontalMove * runVelocity * Time.deltaTime);
            marioStateManager.RunningMario(horizontalMove); // setting running animation

            // jumping
            if (checkGround.IsGrounded())
            {
                if (Input.GetKey(KeyCode.Space))
                {
                    rigidbody.velocity = Vector2.up * jumpForce;
                }
            }
            marioStateManager.JumpingMario(checkGround.IsGrounded()); // setting jump animation
        }
    }