Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

problem with a spawner script

Discussion in 'Scripting' started by giani91, Nov 20, 2015.

  1. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    Code (CSharp):
    1. (var i=0; i<amount; i++){
    2. var spawnPoints : Transform[];  // Array of spawn points to be used.
    3. var Prefabs : GameObject[]; // Array of different Enemies that are used.
    4. var amount = 20;  // Total number of enemies to spawn.
    5. var yieldTimeMin = 2;  // Minimum amount of time before spawning enemies randomly.
    6. var yieldTimeMax = 5;  // Don't exceed this amount of time between spawning enemies randomly.
    7. function Start(){
    8.     Spawn();
    9. }
    10. function Spawn(){
    11.    for (i=0; i<amount; i++){
    12.       yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax));
    13.       var obj : GameObject = Prefabs[Random.Range(0, Prefabs.length)];
    14.       var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)];
    15.       Instantiate(obj, pos.position, pos.rotation);
    16.     }
    17. }  

    the problem say

    assets/dropspawner.js(13,9): BCE0005: Unknown identifier: 'i'.
     
  2. Okto247

    Okto247

    Joined:
    Jun 26, 2015
    Posts:
    7
    I'm missing a curly bracket.
    Is ist true? You want to start the Start-function in a loop?
     
  3. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
    Line 1, copy paste mistake ?
    I think even in Unity-Javascript you can't do loops outside a function ?