Every “Update” when Space is not pressed, the function calls audioSoure.Stop().
Isn’t it better to check first if the sound is being played and only stop in this case?
Just inserted if(audioSource.isPlaying) after else
if(Input.GetKey(KeyCode.Space))
{
rb.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime );
if(!audioSource.isPlaying)
{
audioSource.Play();
}
}
else if(audioSource.isPlaying)
{
audioSource.Stop();
}
I think it could be faster and safer, or am I wrong?