Example #1
0
    private IEnumerator Die()
    {
        BodyParts headPart = head.GetComponent <BodyParts>();

        headPart.AnimateExplosion();
        AudioSource.PlayClipAtPoint(explosionSound, headPart.transform.position);
        yield return(new WaitForSeconds(0.35f));

        Destroy(headPart.gameObject);

        foreach (BodyParts part in bodies)
        {
            part.AnimateExplosion();
            AudioSource.PlayClipAtPoint(explosionSound, part.transform.position);
            yield return(new WaitForSeconds(0.35f));

            Destroy(part.gameObject);
        }

        BodyParts tailPart = tail.GetComponent <BodyParts>();

        tailPart.AnimateExplosion();
        AudioSource.PlayClipAtPoint(explosionSound, tail.transform.position);
        yield return(new WaitForSeconds(0.35f));

        Destroy(tailPart.gameObject);
    }