My rocket audio is getting a reverse effect

The audio doesn’t play when I press the spacebar, but when I let off it plays. I’ve looked it over but I can find any errors.

void ProcessThrust()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            rb.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
            if(!audioSource.isPlaying)
            {
                audioSource.Play();
            }
            else
            {
                audioSource.Stop();
            }
            
        }
    }

Hi Alan,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

At the moment, the audio source gets started/stopped every other frame while the space key is being pressed down.


See also:

Yes It’s identical to the lesson code

Actually compared to the changes in github, it was incorrect. Problem solved. Thank you