I am making a top down 2D game. I have 12 predefined spawn points for enemies, represented by a sprite on screen. on this sprite I have the following script.
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
public class LogicSpawn : MonoBehaviour
{
//RNG
System.Random RNG = new System.Random();
public string Direction;
public Transform DragonPrefabGreen;
public Transform DragonPrefabGold;
//update once per frame
void update()
{
//conects this script to the drgon tracker script
DragonTracker dt = GameObject.Find("_DragonManager").GetComponent();
Timer T2 = GameObject.Find("TimerText").GetComponent();
//spawn logic variables
int RSpawn = RNG.Next(0, 2);
print(RSpawn);
print("RSpawn");
int DragonType = RNG.Next(0, 101);
bool GoldDragonInit = dt.GoldDragonInit;
int DragonCount = dt.DragonCount;
int Difficulty = dt.Difficulty;
//spawning logic
if ((RSpawn == 1) && (DragonCount < Difficulty))
{
if (DragonType > 99)
{
//summon regular dragon
Instantiate(DragonPrefabGreen, transform.position, transform.rotation);
}
if ((DragonType == 100)&&(GoldDragonInit==false))
{
//Sumon gold dragon
Instantiate(DragonPrefabGold, transform.position, transform.rotation);
}
}
}
}
I have a parent game object that all of these sprits are placed beneath in the hierarchy. this game object has a script that contains all of the spawning variables. This keeps track of the current number of enemies in the game, if a special enemy is in play, and to set the difficulty level.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragonTracker : MonoBehaviour
{
// is gold dragon in play?
public bool GoldDragonInit = false;
// curently active dragons
public int DragonCount = 0;
// defalts to 5
public int Difficulty = 5;
}
the problem I am having is the spawning does not appear to work. the only thing I can think of is the random number generator is not working, which Is why I put the print (RSpawn);. nothing appears in the console so it appears that this may be the case but I don't know why it doesn't work.
any help is greatly appreciated.
I will also need to change the variables in the variable tracking script when different events happen, such as an enemy spawns. if anyone could tell me how to do that while I am here that would be great.
thanks is advanced.
↧