Turn camera's sound on/off follow other Gameobject

Hello all,

My scene have a sound background attach to Main Camera, and I want turn it on/off follow hide/unhide of a Plane(play sound if Plane hide, and stop sound if Plane visible). My code run ok but audio error (bumble):

public GameObject Plane;

	void OnGUI () {
		
		if(Plane.activeSelf)
		{
			Camera.main.audio.Stop();


		}else{
			Camera.main.audio.Play();

		}
		
	}

What can i do to fix this error?

Thanks.

Your OnGUI function runs many times per frame and I think your code is basically running Camera.main.audio.Play() over and over again. Add some logic (wrap it in a bool, etc.) to only do that once.