First off, I'm not an english native speaker, so sorry in advance if it's a bit hard to read.
I am developing a 2D shoot'em'up and I've been working on boss fights, enemy scripts, designing backgrounds and other stuff.
If you've played any 2D game you may know that enemies don't appear at random, they do when the camera/player reaches a certain point in the map.
My idea was to create a GameObject and then put inside both camera and player and make it move towards different waypoints and as soon you reach one, an enemy appears with Instantiate and AddComponent.
The question is simple, if you are developing a 2d shoot'em'up/space shooter and you want to instantiate enemies at certain points, what would you do?
Please, don't tell me "there are different ways depending on what you want", I want to know what you would do.
Here's what I have in mind, I haven't tried it out yet, just to show you my idea. Is that what you would do or something completely different?
void Update(){
if (move == true){
cameraAndPlayer.transform.position = Vector3.MoveTowards (cameraAndPlayer.transform.position , waypoints[currentWaypoint].position, speed);
}
if (cameraAndPlayer.transform.position == waypoints[currentWaypoint].transform.position){
if (currentWaypoint == 1){
enemy = Instantiate (Resources.Load ("Prefabs/enemies/enemy1")) as GameObject;
enemy.AddComponent();
}
else if (currentWaypoint == 2){
enemy = Instantiate (Resources.Load ("Prefabs/enemies/enemy2")) as GameObject;
enemy.AddComponent();
}
currentWaypoint++;
}
}
↧