Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //if there's a delay to spawn, keep kicking out of update until delay is gone
        if (startDelay > 0)
        {
            startDelay -= Time.deltaTime;
            return;
        }

        //loop through them all and decrease timers, then reassign once things have been changed
        for (int i = 0; i < spawnLocations.Count; i++)
        {
            RockSpawnLoc loc = spawnLocations[i];
            if (loc.timerCurr <= 0)
            {
                Vector3 vec3Loc = new Vector3(loc.loc.x - spawnerWidth / 2, 0, loc.loc.y);
                Instantiate(rockObj, this.transform.position + vec3Loc, Quaternion.identity);
                loc.timerCurr = loc.timerMax;
            }
            else
            {
                loc.timerCurr -= Time.deltaTime;
            }
            spawnLocations[i] = loc;
        }
    }
Exemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     spawnLocations = new List <RockSpawnLoc>();
     spawnerWidth   = Mathf.RoundToInt(this.GetComponent <SpriteRenderer>().size.x);
     if (singleRockSpawner)
     {
         spawnLocations.Add(new RockSpawnLoc(new Vector2(spawnerWidth / 2, 0), timeBetweenSpawns, timeBetweenSpawns));
     }
     else
     {
         for (int i = 0; i < spawnerWidth; i += rockSpacing)
         {
             float        timerOffset = Random.Range(0, timeBetweenSpawns);
             RockSpawnLoc newSpawn    = new RockSpawnLoc(new Vector2(i, 0), timeBetweenSpawns, timerOffset);
             spawnLocations.Add(newSpawn);
         }
     }
 }