Controlling Audio if camera more out of the scene

is there a way to control other GameObject audio to “OFF” when camera doesn’t see the GameObject?

renderer.isVisible

is the way to find if object is visible. in Update or FixedUpdate function put:

if (!gameObject.renderer.isVisible) audio.Stop();

It can be done from another gameObject too:

if (!other.renderer.isVisible) other.audio.Stop();

Haven’t tested it.

1 Like

hm… its working. but how come after my player crossed more than the gameObject position.y.
e.g. (player position y = 1.01 gameObject position y = 1)
the rederer still is visible but the audio doesnt play.