using UnityEngine; using System.Collections; public class SpawnGoblins : MonoBehaviour { //variables public GameObject goblin; public Transform[] spawnPoints; private GameObject[] goblinSize; public float maxGoblins = 0.0F; public float spawnRate = 0.0F; float timer = 0.0F; private int difficulty; // Use this for initialization void Start () { difficulty = PlayerPrefs.GetInt("difficulty"); //switch the difficulty and based on the difficulty change the kill goals switch(difficulty) { case 0: //leave the settings as they are since they are so easy break; case 1: //change the attacking chances to 50/50 maxGoblins = 25; break; case 2: //change the attacking change to 25 meaning 75% of the time they hit maxGoblins = 50; break; } } // Update is called once per frame void Update () { //find out how many goblins there are in the world goblinSize = GameObject.FindGameObjectsWithTag("Goblin"); timer += Time.deltaTime * 1; if(timer > spawnRate) { for(int i = 0; i < spawnPoints.Length; i++) { if(goblinSize.Length < maxGoblins) Instantiate(goblin, spawnPoints[i].transform.position , spawnPoints[i].transform.rotation); } timer = 0.0F; } } }