20121109

Spawn Script (Javascript)

This script has caused me a lot of problems (trying to get it right). The original script setup meant that whenever a level was made, spawn points would have to be manually added to two arrays (GameManager (C#) and PlayerSpawn(JS). This proved tricky with having over ten respawns, which meant dragging 20 generic spawn points in to the arrays without knowing if I had brought the same one in twice and missed one out. 

I managed to get around this problem by making the spawnPoint prefab include a tag called "SpawnPoint", this would then allow me at the start of a game load up any spawnpoints within the level and automatically slot them in to an array with no fixed length. This means the script now works for a small four player map or a twenty player map.  

OnSignal is what the Player calls when they die, this then resets their variables and places them at one of the spawnpoints throughout the map. 

My problem now with this script, is that when a player respawns and a spawn point theres the chance another player may have instantaneously respawned at the same time in the same spot which causes issues (especially on the character select screen). I need to look in how to make the array globally update for all players, and when a random spawn is assigned it then is removed (RemoveAt) from the array for (WaitForSeconds(X)) seconds and then (Push(Y)) pushed back in.