I am trying to change up my enemies slightly when the user surpasses a certain score. Right now I have an invoke repeating function that starts when the game starts. This works fine, but when the player reaches 50,000 points I wanted to add some extra effects to the enemies. The code I have does not work and I understand why (the invoke repeating is constantly being executed due to being in the update function). I really want to incorporate this in my game, but am unsure on what to do.
Here’s my code:
using UnityEngine;
using System.Collections;
public class GloveSpawner : MonoBehaviour {
public Transform []spawnPoints;
public float spawnTime = 2f;
public GameObject [] Gloves;
public GameObject[] FireGloves;
void Start(){
InvokeRepeating ("SpawnGloves", spawnTime, spawnTime);
}
void Update(){
/*if (ScoreManager.scoreCount >= 50000) {
CancelInvoke ("SpawnGloves");
InvokeRepeating ("SpawnFireGloves", spawnTime, spawnTime);
}*/
}
void SpawnGloves(){
int spawnIndex = Random.Range (0, spawnPoints.Length);
int objectIndex = Random.Range (0, Gloves.Length);
Instantiate (Gloves [objectIndex], spawnPoints [spawnIndex].position, spawnPoints [spawnIndex].rotation );
}
void SpawnFireGloves(){
int spawnIndex = Random.Range (0, spawnPoints.Length);
int objectIndex = Random.Range (0, FireGloves .Length);
Instantiate (FireGloves [objectIndex], spawnPoints [spawnIndex].position, spawnPoints [spawnIndex].rotation);
}
}