galaboy
1
am doing a space shooter game where i need to make enemies. i want to make instance of the enemies. should i have to use for loop for multiple instanciations. if so can any one tell how. i have never tried like this before. i need a start. need help.
ramp
3
Hi,use this code in java script.instantiate 10 object random with space 2 from each other in game view.
var prefab : Transform;
function Example()
{
for (var i : int = 0;i < 10; i++) {
Instantiate (prefab, Vector3(i * 2.0, 0, 0), Quaternion.identity);
}
}
gajdot
2
Yes, you need a for loop or while. You could look at this documentation:
Basically the first example is what you need, the only thing you could change to add an array of transform and use it’s coordinates to spawn enemies like this:
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
public Transform[] spawnLocations;
public gameObject prefab;
void Example() {
int i = 0;
while (i < 10) {
Instantiate(prefab, spawnLocations_.position, spawnLocations*.rotation)*_
i++;
}
}
}
And just set up the spawnLocations by adding the spawnlocations from the inspector panel.