コード例 #1
0
    void OnTriggerExit(Collider otherCollider)
    {
        if (otherCollider.tag == "JumpingArea")
        {
            animator.SetBool("OnGround", false);
        }
        else if (otherCollider.tag == "WallJumpingArea")
        {
            canWallJump = false;
        }

        if (otherCollider.GetComponent <SpeedArea> () != null)
        {
            SpeedArea speedArea = otherCollider.GetComponent <SpeedArea> ();
            if (speedArea.direction == Direction.Left)
            {
                onSpeedAreaLeft = false;
            }
            else if (speedArea.direction == Direction.Right)
            {
                onSpeedAreaRight = false;
            }
        }

        if (otherCollider.GetComponent <LongJumpBlock> () != null)
        {
            onLongJumpBlock = false;
        }
    }
コード例 #2
0
    void OnTriggerEnter(Collider otherCollider)
    {
        // Collect coins.
        if (otherCollider.transform.GetComponent <Coin> () != null)
        {
            Destroy(otherCollider.gameObject);
            onCollectCoin();
        }

        // Speed up or down.
        if (otherCollider.GetComponent <SpeedArea> () != null)
        {
            SpeedArea speedArea = otherCollider.GetComponent <SpeedArea> ();
            if (speedArea.direction == Direction.Left)
            {
                onSpeedAreaLeft = true;
            }
            else if (speedArea.direction == Direction.Right)
            {
                onSpeedAreaRight = true;
            }
        }

        // Perform long jump.
        if (otherCollider.GetComponent <LongJumpBlock> () != null)
        {
            onLongJumpBlock = true;
        }

        // Kill the player when they touch the enemy.
        if (otherCollider.GetComponent <Enemy> () != null)
        {
            Enemy enemy = otherCollider.GetComponent <Enemy> ();
            if (hasInvincibility == false && enemy.Dead == false)
            {
                if (hasPowerUp == false)
                {
                    Kill();
                }
                else
                {
                    hasPowerUp = false;
                    model.transform.localScale = Vector3.one;
                    ApplyInvincibility();
                }
            }
        }

        // Collect the PowerUp.
        if (otherCollider.GetComponent <PowerUp> () != null)
        {
            PowerUp powerUp = otherCollider.GetComponent <PowerUp> ();
            powerUp.Collect();
            ApplyPowerUp();
        }

        // Reach the finish line.
        if (otherCollider.GetComponent <FinishLine> () != null)
        {
            hasInvincibility = true;
            finished         = true;
        }
    }