Audio Source "Success" sound not playing

So, I noticed that some people were having trouble getting the sound for the “success” to play when colliding with it. After some experimenting with the code, it seems like the issue is with the ProccessThrust() method from the Movement Script.

Since we are instructed to disable ‘Movement.cs’ within the ‘CollisionHandler.cs’, the sound is allowed to play for both the finsihSequence and crashSequence method because it is within the Movement.cs that we call the Stop() method for ALL sounds.

Therefore if you DO NOT disable the Movement.cs from within the CollisionHandler.cs, you will not hear any sounds because of the aforementioned Stop() method.

CollisionHandler.cs

void StartFinishSeq()
    {
        mAudio.PlayOneShot(successSound);
        GetComponent<Movement>().enabled = false;
        Invoke("LoadNextLevel", timer);
    }

    void StartCrashSeq()
    {
        //todo add sfx upon crash
        //todo add particle effect upon crash
        GetComponent<Movement>().enabled = false;
        mAudio.PlayOneShot(failSound);
        Invoke("ReloadLevel", timer);

Movement.cs

void ProcessThrust()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            if (myAudio.isPlaying != true)
            { 
                myAudio.PlayOneShot(mainEngine);
            }
            rb.AddRelativeForce(Vector3.up * playerThrust * Time.deltaTime);
        }
        else
        {
            myAudio.Stop();
        }
    }

To be clear. The Stop() method applies to EVERY sound. So if you fail to disable the Movement.cs script, any other sound you try to play won’t work.

2 Likes

Privacy & Terms