1

I am currently making a simple side-scroller. In unity. I am looking for a way to spawn objects before they enter camera, and remove them after they have passed the camera. All this will happn in the x axis.

There are 6 different kinds of objects that are going to be spawned. and with different distence from each other. The objects can be picked up, and they are all prefabs and have the functional scripts for pickup if the player collide. But I need a way to remove them if they didn't get picked up.

Is there anyone that have a simple script where this will be possible?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Eyrik
  • 127
  • 3
  • 13

1 Answers1

1

there is a 2 methods in MonoBehaviour you can use: OnBecameInvisible and OnBecameVisible. they are called whenever the renderer is no longer visible (or becone visible) by any camera.

SentineL
  • 4,682
  • 5
  • 19
  • 38
  • onbecameinvisbile can be used for my script. but how can i do it about the spawning, when they need to spawn before they come into the screen? – Eyrik Dec 13 '12 at 13:41
  • spawn tham where ever you whant. When GameObject is creating, `Awake` method on every script is calling. then, chack out `Renderer.isVisible` field to know if it is visible at the moment and act as you whant. – SentineL Dec 13 '12 at 14:57