using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SpawnerEnemy : MonoBehaviour {
public Text Wavetext;
public GameObject []enemies;
int[] wave;
int Cwave = 0;
Vector3 positionofspawn;
float x;
float z;
// Use this for initialization
void Start () {
wave [0] = 15;
positionofspawn= new Vector3(transform.position.x,transform.position.y,transform.position.z);
x = transform.position.x;
z = transform.position.z;
}
// Update is called once per frame
void Update () {
if (GameObject.FindGameObjectsWithTag ("enemy").Length <1 ) {
for (int i = 0 ; i < wave [Cwave]; i++ ) {
int enemyToSpawn = Random.Range (0, enemies.Length);
positionofspawn.x = Random.Range(80 , -80);
positionofspawn.z = Random.Range(80 , -80);
Instantiate (enemies [enemyToSpawn], positionofspawn, Quaternion.identity);
}
wave [Cwave + 1] = wave [Cwave += 15];
Cwave++;
Wavetext.text = Cwave.ToString () + " " + wave [Cwave].ToString ();
}
}
}
this is my script , what I want is that every next wave num of enemeis is 15+ . I get NullReferenceException: Object reference not set to an instance of an object
SpawnerEnemy.Update () (at Assets/codes/SpawnerEnemy.cs:32)
but when I add numbers in wave it works int wave = {15,30,45…} I want it to make like this so it dosent come to the end .