- Home /
Question by
hallonkatastrof · Jun 29, 2016 at 05:44 PM ·
c#spawningenemiesfrequency
Unity2D spawn frequency not working C#
My current script spawns enemies randomly within the given area, but the spawn frequency ("spawnTime") is not working. Although changing it, nothing changes, why?
using UnityEngine;
using System.Collections;
public class spawnScript : MonoBehaviour
{
public float spawnTime;
public GameObject[] objects;
private Vector2 spawnPosition;
void Start ()
{
InvokeRepeating ("Spawn", spawnTime, spawnTime);
objects = GameObject.FindGameObjectsWithTag ("enemy");
}
void FixedUpdate () {
}
// Update is called once per frame
void Update () {
objects = GameObject.FindGameObjectsWithTag ("enemy");
}
void Spawn ()
{
spawnPosition.x = Random.Range (10.38f, 18f);
spawnPosition.y = Random.Range (4.4f, -3.38f);
Instantiate (objects[UnityEngine.Random.Range(0, objects.Length)], spawnPosition, Quaternion.identity);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Enemies spawn on top of each other(C#)(Unity) 1 Answer
C# - spawn limit not working properly. 1 Answer
Spawning A Grid Of Cubes 2 Answers