- Home /
JS: Dump array value in an Enum
Hey guys. Im trying to make a spawning system for our game. We want it to work entirely through the inspector.
We start off setting the GameObjects to spawn, then set the amount of waves and amount of pushes within each wave. Finally we set which game objects spawn and how many of them.
(im really sorry this code isnt linked correctly, that 101 010 button isn't doing anything for me)
var enemies : GameObject[];
var amountOfWaves : WaveAmount[];
class WaveAmount
{
var wavePushes : WavePushes[];
}
class WavePushes
{
var startTimeSinceLastPush : float;
var enemyBuild : Composition[];
}
class Composition
{
var Spawn1 : EnemyList;
var spawn1Count : int;
var Spawn2 : EnemyList;
var spawn2Count : int;
var Spawn3 : EnemyList;
var spawn3Count : int;
}
enum EnemyList
{
enemies[0],
enemies[1],
enemies[2]
}
The problem is that it doesnt work at all. Perhaps im going about this situation all wrong, but i haven't been doing this for very long and im kind of lost.
Trying to link the array to the enum and them back into the class isnt working ... if its possible at all.
If it changes anything, we hope to use those enum values inside the Update function to instantiate them based on the spawnXCount.
i edited the code a little bit to remove all the needless duplicates (was a much longer enum list, etc)
Enums are compile-time constructs for na$$anonymous$$g things. This means, they must have a value at compile-time and thus expressions are not suitable, as they might evaluate to different values during run-time.
In C#, enums are basically named ints.
Ah i see, thank you Jamora.
So ive changed it a little bit and its working as planned now.
// top
var enemies1 : GameObject;
var enemies2 : GameObject;
var enemies3 : GameObject;
//bottom
enum EnemyList
{
enemies1,
enemies2,
enemies3
}
and it looks great in the inspector too. tyvm Jamora
No problem. You should either convert your comment to an answer or post your solution as an answer, and then mark it as correct.
Answer by iHunterKiller · Mar 04, 2014 at 10:16 PM
The error was in trying to use an array. Jamora helped me solve it :)
Change the top and bottom of the original code to the below. Now i have to sort out the spawning ^^ Perhaps a coroutine
// top
var enemies1 : GameObject;
var enemies2 : GameObject;
var enemies3 : GameObject;
//bottom
enum EnemyList
{
enemies1,
enemies2,
enemies3
}
Your answer
Follow this Question
Related Questions
Zombie Wave Spawning script 1 Answer
Spawn "n" Enemies Every "nth" Wave? 1 Answer
How to prevent infinite loop when Array Index Is Out Of Range 2 Answers
Instantiate 1 at a time at each transform in array 1 Answer
Can I call a function on a behavior attached to a prefab from it's spawner object? 1 Answer