Combined Start[Crash/Success]Sequence

I didn’t like the StartCrashSequence and StartSuccessSequence were basically the same code, so I combined them to clean things up.

private void OnCollisionEnter(Collision other) {

        if (isTransitioning) { return; }

        if (isCollisionOff) { return; }

        switch(other.gameObject.tag) {

            case "Friendly":

                Debug.Log("Friendly");

                break;

            case "Finish":

                StartTransitionSequence("LoadNextLevel", successAudio, successParticles);

                break;

            default:

                StartTransitionSequence("ReloadScene", crashAudio, crashParticles);

                break;

        }

    }

    void StartTransitionSequence(string transitionMethod, AudioClip transitionAudio, ParticleSystem transitionParticles) {

        TogglePlayerControls();

        audioSource.Stop();

        audioSource.PlayOneShot(transitionAudio);

        transitionParticles.Play();

        Invoke(transitionMethod, reloadDelay);

        isTransitioning = true;

    }

Privacy & Terms