Search Unity

My game wont run after going in main menu

Discussion in 'Getting Started' started by time2die418, Feb 1, 2019.

  1. time2die418

    time2die418

    Joined:
    Feb 1, 2019
    Posts:
    1
    My game stops after going in the main menu can someone help me

    this is my code


    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;

    public class WaveSpawner : MonoBehaviour
    {
    public static int EnemiesAlive = 0;

    public Wave[] waves;

    public Transform spawnPoint;

    public float timeBetweenWaves = 5f;
    private float countdown = 2f;

    public Text waveCountDownText;

    public GameManager gameManager;

    public GameObject nextWaveUI;

    private int waveIndex = 0;

    void Update()
    {
    if (EnemiesAlive > 0)
    {
    return;
    }

    if (waveIndex == waves.Length)
    {
    gameManager.Winlevel();
    this.enabled = false;
    }

    if (countdown <= 0f)
    {
    StartCoroutine(SpawnWave());


    countdown = timeBetweenWaves;
    return;
    }

    timez();
    nextWaveUI.SetActive(true);
    waveCountDownText.enabled = true;

    }

    IEnumerator SpawnWave()
    {
    PlayerStats.Rounds++;

    Wave wave = waves[waveIndex];

    EnemiesAlive = wave.count;

    for (int i = 0; i < wave.count; i++)
    {
    SpawnEnemy(wave.enemy);
    yield return new WaitForSeconds(1f / wave.rate);
    }

    waveIndex++;
    }

    void SpawnEnemy (GameObject enemy)
    {
    Instantiate(enemy, spawnPoint.position, spawnPoint.rotation);
    }

    public void Nextwave()
    {
    countdown = 0f;
    waveCountDownText.text = "00.00";
    waveCountDownText.enabled = false;
    nextWaveUI.SetActive(false);
    return;
    }

    public void timez()
    {
    countdown -= Time.deltaTime;
    countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);
    waveCountDownText.text = string.Format("{0:00.00}", countdown);
    }
    }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    How are you debugging? What code is running when you select your menu? You'll want to step debug through your code to determine what is going on. Alternatively (and easier), make generous use of Debug.Log statements that will show in your Console window, and in device logs.