hi i currently want to have a boss fight in my game (im taking unity tutorial "Space Shooter"and expanding it)
but i cant get the script to work i have a timer that when it gets to 20 count than spawn the boss but its not doing that heres my script so far:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Gameplayer : MonoBehaviour {
public GameObject[] hazards;
public GameObject boss;
public Vector3 spawnval;
public int hazardcnt;
public float spawnwait;
public float startwait;
public float wavewait;
public GUIText restarttext;
public GUIText gameovertxt;
public GUIText scoreText;
private int score;
public float incrementtime = 1f;
public float incrementby = 1;
private float counter = 0;
private bool gameover;
private bool restart;
void Start () {
InvokeRepeating("Increment", incrementtime, incrementby);
if (counter == 10) {
bossfight();
}
restart = false;
restarttext.text = "";
gameovertxt.text = "";
gameover = false;
score = 0;
StartCoroutine (Spawnstuff ());
UpdateScore ();
}
void Update() {
if (restart) {
if (Input.GetKey(KeyCode.R)){
Application.LoadLevel(Application.loadedLevel);
}
}
}
IEnumerator Spawnstuff () {
yield return new WaitForSeconds(startwait);
while(true) {
for (int i = 0; i < hazardcnt; i++)
{
GameObject hazard = hazards[Random.Range (0, hazards.Length)];
Vector3 spawnpos = new Vector3 (Random.Range(-spawnval.x, spawnval.x), spawnval.y, spawnval.z);
Quaternion spawnrot = Quaternion.identity;
Instantiate (hazard, spawnpos, spawnrot);
yield return new WaitForSeconds(spawnwait);
}
yield return new WaitForSeconds (wavewait);
if (gameover) {
restarttext.text = "press 'r' for restart";
restart = true;
break;
}
}
}
public void AddScore (int newScoreValue)
{
score += newScoreValue;
UpdateScore ();
}
void UpdateScore ()
{
scoreText.text = "Score: " + score;
}
public void GameOver() {
gameovertxt.text = "Game Over";
gameover = true;
}
void bossfight (){
Vector3 spawnpos = new Vector3 (spawnval.x, spawnval.y, spawnval.z);
Quaternion spawnrot = Quaternion.identity;
Instantiate (boss, spawnpos, spawnrot);
}
void Increment () {
counter += incrementby;
}
}