- Home /
How can i make sound when the gameobject exit the camera?
Hello guys i'm still beginner, i'm stucked, i want to make a sound when my gameobject exit the camera bounds. My script doesn't work : if (gameObject.transform.position.y > Screen.height || gameObject.transform.position.y < 0) { AirSound (); }
Answer by VinceC80 · Jun 22, 2017 at 07:13 PM
Try using Debug.Log() to output your position and height variables. I think you'll find that the Screen.height is much higher, because this outputs the height in pixels. The gameObject.transform.position.y likely be much lower, because this is not in pixels. You may want to just drag your object onto the screen (when not in play mode), and drag the object to the upper and lower bounds of the camera, denote the y position, and use those are your max and min coordinates.
Note: gameObject.transform.position.y < 0 should actually alert anytime the object is below the middle part of your screen, assuming your camera is centered.
Your answer
![](https://koobas.hobune.stream/wayback/20220612124713im_/https://answers.unity.com/themes/thub/images/avi.jpg)