- Home /
Spawn random enemies in 2D
Hello :) i'm a beginner on making games in 2d, and i dont know how to spawn in a random position my enemies in 2d, i'm currently working with unity 4.6 and it's difficult to find a code that works. thank you for helping me
Answer by furic · Apr 16, 2015 at 02:17 AM
Instantiating Prefabs at runtime
Instantiate(enemyGameObject, new Vector3(Random.Range (-200, 200), Random.Range (-200, 200), 0), Quaternion.identity);
The number 200 is depended on your camera size, move a object around to find what's your screen height/width to x/y position.
Hello, I am also a beginner, would this line of code go on my spawning class? - what would a collector class look like to deactivate the object?
Your answer
Follow this Question
Related Questions
Spawn origin point!! 0 Answers
Unity 4.6 Stop Canvas from flipping 1 Answer
Phantom Instantiation at Origin 0 Answers
What is the best way to spawn enemies? 3 Answers
How to spawn a prefab on a trigger? 3 Answers