I have a small game that I have working on for a couple of months already. But my problem is this script…
using System.Collections;
using System.Collections.Generic;
using UnityEditor.UIElements;
using UnityEngine;
public class spawner : MonoBehaviour
{
//This is GameObject[]
[SerializeField] private GameObject[] Entities;
[SerializeField] public GameObject[] EntitiespatEasy;
[SerializeField] public GameObject[] EntitiespatModerate;
[SerializeField] public GameObject[] EntitiespatHard;
[SerializeField] public GameObject[] EntitiespatVeryHard;
[SerializeField] public GameObject[] EntitiespatGodmode;
private float TimebtwSpawn;
public float StartTimebtwSpawn;
public float decreaseTime;
public float minTime = 0.65f;
private int numspawn;
// Update is called once per frame
void Update()
{
Difficutlyrating();
}
//This wil be for Beginner
private void Spawnedthem()
{
//This scripts able to force spawn
if (TimebtwSpawn <= 0)
{
int rand = Random.Range(0, Entities.Length);
Instantiate(Entities[rand], transform.position, Quaternion.identity);
TimebtwSpawn = StartTimebtwSpawn;
if (TimebtwSpawn > StartTimebtwSpawn)
{
StartTimebtwSpawn -= decreaseTime;
}
}
else
{
TimebtwSpawn -= Time.deltaTime;
}
}
//This proviate the information what what to spawn
void Difficutlyrating()
{
if(numspawn <= 20)
{
Debug.Log("Beginner");
Debug.Log("Numspawn");
if (TimebtwSpawn <= 0)
{
int rand = Random.Range(0, Entities.Length);
Instantiate(Entities[rand], transform.position, Quaternion.identity);
TimebtwSpawn = StartTimebtwSpawn;
if (TimebtwSpawn > StartTimebtwSpawn)
{
StartTimebtwSpawn -= decreaseTime;
}
numspawn++;
}
else
{
TimebtwSpawn -= Time.deltaTime;
numspawn++;
}
}
//Easy
if (numspawn <= 40)
{
Debug.Log("Easy");
Debug.Log("Numspawn");
if (TimebtwSpawn <= 0)
{
int rand = Random.Range(0, EntitiespatEasy.Length);
Instantiate(EntitiespatEasy[rand], transform.position, Quaternion.identity);
TimebtwSpawn = StartTimebtwSpawn;
if (TimebtwSpawn > StartTimebtwSpawn)
{
StartTimebtwSpawn -= decreaseTime;
}
numspawn++;
}
else
{
TimebtwSpawn -= Time.deltaTime;
numspawn++;
}
}
//Moderate
else if (numspawn <= 60)
{
Debug.Log("Moderate");
Debug.Log("Numspawn");
if (TimebtwSpawn <= 0)
{
int rand = Random.Range(0, EntitiespatModerate.Length);
Instantiate(EntitiespatModerate[rand], transform.position, Quaternion.identity);
TimebtwSpawn = StartTimebtwSpawn;
if (TimebtwSpawn > StartTimebtwSpawn)
{
StartTimebtwSpawn -= decreaseTime;
}
numspawn++;
}
else
{
TimebtwSpawn -= Time.deltaTime;
numspawn++;
}
}
//Hard
else if (numspawn <= 80)
{
Debug.Log("Hard");
Debug.Log("Numspawn");
if (TimebtwSpawn <= 0)
{
int rand = Random.Range(0, EntitiespatHard.Length);
Instantiate(EntitiespatHard[rand], transform.position, Quaternion.identity);
TimebtwSpawn = StartTimebtwSpawn;
if (TimebtwSpawn > StartTimebtwSpawn)
{
StartTimebtwSpawn -= decreaseTime;
}
numspawn++;
}
else
{
TimebtwSpawn -= Time.deltaTime;
numspawn++;
}
}
//Very Hard
else if (numspawn <= 100)
{
Debug.Log("Very Hard");
Debug.Log("Numspawn");
if (TimebtwSpawn <= 0)
{
int rand = Random.Range(0, EntitiespatVeryHard.Length);
Instantiate(EntitiespatVeryHard[rand], transform.position, Quaternion.identity);
TimebtwSpawn = StartTimebtwSpawn;
if (TimebtwSpawn > StartTimebtwSpawn)
{
StartTimebtwSpawn -= decreaseTime;
}
numspawn++;
}
else
{
TimebtwSpawn -= Time.deltaTime;
numspawn++;
}
}
//GodeMode
else if (numspawn >= 100)
{
Debug.Log("God Mode");
Debug.Log("Numspawn");
if (TimebtwSpawn <= 0)
{
int rand = Random.Range(0, EntitiespatGodmode.Length);
Instantiate(EntitiespatGodmode[rand], transform.position, Quaternion.identity);
TimebtwSpawn = StartTimebtwSpawn;
if (TimebtwSpawn > StartTimebtwSpawn)
{
StartTimebtwSpawn -= decreaseTime;
}
numspawn++;
}
else
{
TimebtwSpawn -= Time.deltaTime;
numspawn++;
}
}
}
}
The problem with the script is that is numspawn counting up even the entities haven’t spawned yet and it just went to the Godmode right on the spot. I know the core problem is the numspawn part but how am I going to solve this. Please help me! I’m quite a C# noob.