示例#1
0
    void OnTriggerEnter(Collider other)
    {
        //check if we hit an obstacle, and if so die
        if (other.gameObject.CompareTag("Obstacle"))
        {
            if (bullet)
            {
                return;
            }
            else if (wasBullet)
            {
                wasBullet = false;
                other.gameObject.SetActive(false);

                return;
            }

            Die();

            return;
        }

        //if we're a bullet, break everything
        if (bullet && (other.gameObject.CompareTag("Breakable") || other.gameObject.CompareTag("Platform")))
        {
            Platform platform = other.transform.parent.GetComponent <Platform>();
            platform.Break(transform.position);

            return;
        }

        //stop here if the animation is playing
        //if(animPlaying)
        //	return;

        //if we're just jumping, play the jump animation
        if (!fullForce)
        {
            StartCoroutine(Anim());
        }
        else if (!prepareBreak)
        {
            //otherwise, check if we can break through a gate and die otherwise
            if (other.gameObject.transform.parent.CompareTag("Fractured"))
            {
                return;
            }

            fullForce = false;

            if (other.gameObject.CompareTag("Breakable"))
            {
                Platform platform = other.transform.parent.GetComponent <Platform>();
                platform.BreakCenter();

                //shake the camera for a nice effect
                StartCoroutine(cam.Shake(0.1f, 0.15f));

                powerup.AddPower();

                //rb.velocity = Vector3.up * -force;
            }
            else
            {
                Die();
            }
        }
    }