示例#1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.gameObject.CompareTag(Strings.Tags.player))
        {
            //Calculate the magnitude of the explosion based on collision distance from center
            Vector2 collisionPoint     = collision.GetContact(0).point;
            float   collisionDistance  = (collisionPoint - rb.position).magnitude;
            float   explosionMagnitude = 1f - collisionDistance / maxCollisionDistance;

            //Instantiate an explosion particle effect with appropriate magnitude
            GameObject          explosionInstance   = Instantiate(explosion, rb.position, Quaternion.Euler(0, 0, rb.rotation)) as GameObject;
            ExplosionController explosionController = explosionInstance.GetComponent <ExplosionController>();
            explosionController.SetMagnitude(explosionMagnitude);

            //Play explosion sound
            playExplosionSound(explosionMagnitude);

            //Vibrate device
            explosionVibrate(explosionMagnitude);

            //Slow Time
            explosionTimeSlow(explosionMagnitude);

            Destroy(this.gameObject);

            //I put in lots of effot to make gate hits impactful :)
        }
    }