Exemplo n.º 1
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll == null)
        {
            return;
        }

        //Hit a brick
        if (coll.gameObject.layer == bricksLayer && _alreadyHitBrick != true)
        {
            Brick brick = HitBrickWithHead();
            //Debug.Log("hit "+coll.gameObject.name+" "+(brick==null));
            if (brick != null)
            {
                brick.OnHit(gameObject);
                _alreadyHitBrick = true;
            }
        }

        //Hit an enemy
        else if (coll.gameObject.layer == enemyLayer || coll.gameObject.layer == runningEnemyLayer)
        {
            Enemy enemy = coll.contacts[0].collider.gameObject.GetComponent <Enemy>();
            if (enemy != null)
            {
                //mario stomped the enemy
                if (HasStomped(coll))
                {
                    _motion.Jump();
                    _score += enemy.Stomped(this);
                    _audio.PlayOneShot(KillEnemyClip);
                }
                //mario collided with the enemy
                else if (star != null)
                {
                    _score += enemy.pointsWhenKilled;
                    enemy.Kill();
                }
                else
                {
                    enemy.OnMarioContact(this, coll);
                }
            }
        }
    }
Exemplo n.º 2
0
    public void JumpWithAnimate(bool max)
    {
        if (_animator.GetBool("isJumping"))
        {
            return;
        }

        _canJump = false;
        _animator.SetBool("isJumping", true);
        _animator.SetTrigger("Jump");
        _animator.ResetTrigger("dash");

        _marioMovement.Jump(max);

        var soundmanager = SoundManager.getinstance();

        if (soundmanager != null)
        {
            soundmanager.Play(SoundManager.eIdentify.jump);
        }
    }