- Home /
Attach enemy-spawner beside camera
I make a 2D game where the player moves only upwards when you press a button, the goal is to get as high as possible without hitting any enemys in the sky (the enemys spawn outside the camera and move only horizontally through the screen).
My question is how i attach the enemy spawner to the camera, because if i just put the spawner static beside the camera, the enemys spawn in the view if the screen is wider and they spawn to far away if the screen is more narrow.
So what is the best way to make the game as responsive as possibel?
Answer by OneCept-Games · Jan 03, 2018 at 09:56 AM
Make the Spawner GameObject a child of your Camera, and place it just out of visibility of the field of view. Then when you spawn your objects it will always be from same point related to the view. If you spawn enemies from above, and are only moving upwards, and the camera can only move up, then you could have a Random.Range(x1,x2) where x1 and x2 are the left and right side of your view, then your enemies are spawning randomly accross your screen.
I have already tried this but it only resizes if I change the size of the transform, but if the screen size changes the scale always stays the same.
ok, then reposition the spawn object related to screen size or use Anchors in a RectTransform.
https://docs.unity3d.com/$$anonymous$$anual/HOWTO-UI$$anonymous$$ultiResolution.html
Yea but how do i reposition the object the rect transform does not work neither. And to put the spawner into the UI is not a good idea.