#ok i can do that
1 messages · Page 1 of 1 (latest)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
public GameObject[] spawners;
public GameObject[] enemy;
public int dice = 10;
private int enemyChance;
private int enemyChoice;
public int spawnAmount = 10;
private int spawnerSelector;
private float delayFinal;
public float delayMin = 5.0f;
public float delayMax = 8.0f;
public Difficulty difficulty;
public Brain brain;
public bool spawnDone;
public int enemiesRemaining;
// Start is called before the first frame update
void Start()
{
spawnDone = true;
enemiesRemaining = 0;
}
// Update is called once per frame
void Update()
{
spawners = GameObject.FindGameObjectsWithTag("spawner");
if (enemiesRemaining == 0 && spawnDone == true)
{
StartCoroutine(Spawn());
spawnDone = false;
}
}
public IEnumerator Spawn()
{
for (int i = 0; i < spawnAmount; i++)
{
//get chance for each enemy wighted by dice. I get enemy chance which is a range from 0/dice and use the outcome to select which monster to spawn.
enemyChance = Random.Range(0, dice);
if (enemyChance < 70)
{
enemyChoice = 0;
}
else if (enemyChance > 70 && enemyChance < 90)
{
enemyChoice = 1;
}
else if (enemyChance >= 90)
{
enemyChoice = 2;
}
spawnerSelector = Random.Range(0, spawners.Length);
Instantiate(enemy[enemyChoice], spawners[spawnerSelector].transform.position, enemy[enemyChoice].transform.rotation);
delayFinal = Random.Range(delayMin, delayMax);
yield return new WaitForSeconds(delayFinal);
}
spawnDone = true;
difficulty.IncreaseDifficulty();
}
}
whats the error
i pick a random enemy from the list of enemies
then i pick a random location from a list of spawners
then i pick a random delay between a minimum amount of time and a maximum amount of time
after all of that i want the wave to end
when the wave ends those 3 things are set to be harder next round
and when the character enters and then exits the shop the next round will begin
the dice variable is so that I can gate the percentage chance of each mob, so in the first few rounds it will only be the basic enemy, then a small percent of the next ememy, and eventually a predetermined chance to spawn all 3
this is the error
NullReferenceException: Object reference not set to an instance of an object
moveTp.Start () (at Assets/Scripts/moveTp.cs:13)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveTp : MonoBehaviour
{
private GameObject goal;
private GameObject spawner;
// Start is called before the first frame update
void Start()
{
spawner = GameObject.FindGameObjectWithTag("SpawnManager");
spawner.GetComponent<Spawner>().enemiesRemaining += 1;
goal = GameObject.FindGameObjectWithTag("goal");
UnityEngine.AI.NavMeshAgent agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
agent.destination = goal.transform.position;
}
// Update is called once per frame
void Update()
{
}
}
its in this script for the enemy
its a temporary script, im just trying to get the backend spawning and pathfinding working so i can start designing the gameplay
Do you have a mic?
sure