am doing a 2d sidescroller game where, i want to destroy a gameobject that moves out of range from camera. is there any way to achieve this like camera.range, camera.bounds etc. need help.
1 Answer
1You can use Renderer.OnBecameInvisible
This method will be called when the object is no longer visible by any camera
public class DestroyOnInvisible : MonoBehaviour {
public void OnBecameInvisible() {
Destroy(gameObject);
}
}
thanks for the explanation.
– galaboy