I am creating a game for android in unity 5 and I need to use this script , I used formerly with Unity 4.5 but now does not work
var spawnPoints : Transform[]; // Array of spawn points to be used.
var Prefabs : GameObject[]; // Array of different Enemies that are used.
var amount = 20; // Total number of enemies to spawn.
var yieldTimeMin = 2; // Minimum amount of time before spawning enemies randomly.
var yieldTimeMax = 5; // Don't exceed this amount of time between spawning enemies randomly.
function Start(){
Spawn();
}
function Spawn(){
for (i=0; i<amount; i++){
yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax));
var obj : GameObject = Prefabs[Random.Range(0, Prefabs.length)];
var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)];
Instantiate(obj, pos.position, pos.rotation);
}
}
I tried everything but I managed to solve the problem
The most common, least helpful phrase on the forums. “Doesn’t work” doesn’t say anything. Different error message? Same error message? Also, there were two suggestions given there, which one did you try? or did you try both?
(“var i” is absolutely and exactly the solution, btw, so if you tried that and you’re still getting the same error…maybe you forgot to hit save? Don’t know what else to tell you)
I am new to unity and not used very well could you help me create the script that is to say that I did not know how to correct the problem with your suggestion
Exactly what @Suddoha suggested. The first suggestion, in particular (the second one would only work in C#). I honestly don’t think I can make it any clearer than he did.
Assets/dropspawner.js(1,2): BCE0043: unexpected token: var and other look the pic
i use this script wih your modification
(var i=0; i<amount; i++){
var spawnPoints : Transform[]; // Array of spawn points to be used.
var Prefabs : GameObject[]; // Array of different Enemies that are used.
var amount = 20; // Total number of enemies to spawn.
var yieldTimeMin = 2; // Minimum amount of time before spawning enemies randomly.
var yieldTimeMax = 5; // Don't exceed this amount of time between spawning enemies randomly.
function Start(){
Spawn();
}
function Spawn(){
for (i=0; i<amount; i++){
yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax));
var obj : GameObject = Prefabs[Random.Range(0, Prefabs.length)];
var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)];
Instantiate(obj, pos.position, pos.rotation);
}
}