- Home /
How to enable sprite only when camera sees it?
Hi all,
This is my first question here. Hello! :)
I am building a platform game and I have build the scene statically. Have created all my elements in that scene, added my enemies and all that. The enemies walk towards the player when the scene starts.
What I actually want is to have the enemies disabled/frozen and only enabled when the camera actually seems them. I tried the OnBecameVisible() method but the method is called when the scene starts... Maybe because the Enemies are already defined in the scene?
Thank you
I got it guys. I added the following method to the script attached to the camera: void LateUpdate() { //The lines below are locking the camera in its Y position. If you want to //Have the camera following the player when he jumps, comment this out Vector3 a = gameObject.transform.position; a.y = 0.05f; gameObject.transform.position = a; }
Basically locking the camera's Y position and giving it a small offset. Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220611234902im_/https://answers.unity.com/themes/thub/images/avi.jpg)