|
|
@ -13,9 +13,9 @@ public class blockSpawn : MonoBehaviour |
|
|
|
|
|
|
|
List<ClientData> ConnectedClients; |
|
|
|
public ClientList clientDataList; |
|
|
|
public Block[] SpawnBlocks; |
|
|
|
public List<Block> SpawnBlocks; |
|
|
|
List<Vector3> spawnedLocations; |
|
|
|
List<Block> possibleSpawnLocations; |
|
|
|
public List<Block> possibleSpawnLocations; |
|
|
|
int spawnNumber = 2; |
|
|
|
|
|
|
|
void Awake() |
|
|
@ -26,8 +26,8 @@ public class blockSpawn : MonoBehaviour |
|
|
|
} |
|
|
|
public void wakeup() |
|
|
|
{ |
|
|
|
SpawnBlocks.ToList().Clear(); |
|
|
|
SpawnBlocks = FindObjectsOfType<Block>().Where(p => p.isCollectableSpawnable).ToArray(); |
|
|
|
SpawnBlocks.Clear(); |
|
|
|
SpawnBlocks = FindObjectsOfType<Block>().Where(p => p.isCollectableSpawnable).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
public void Spawn() |
|
|
@ -36,13 +36,15 @@ public class blockSpawn : MonoBehaviour |
|
|
|
ConnectedClients.Sort((b, a) => a.playerCharacter.transform.position.x.CompareTo(b.playerCharacter.transform.position.x)); |
|
|
|
|
|
|
|
//add two to each to set bounds
|
|
|
|
int min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x + 3; |
|
|
|
int max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x + 2; |
|
|
|
int min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x; |
|
|
|
int max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x +2; |
|
|
|
//Debug.Log("Min x: " + min_x + " max x: " + max_x);
|
|
|
|
|
|
|
|
//Check points within the bounds of players
|
|
|
|
foreach(Block point in SpawnBlocks) |
|
|
|
{ |
|
|
|
if(point.transform.position.x > min_x && point.transform.position.x < max_x) |
|
|
|
//Debug.Log("Position: " + point.transform.position.x + " and " + point.transform.position.z);
|
|
|
|
if(point.transform.position.x >= min_x && point.transform.position.x <= max_x) |
|
|
|
{ |
|
|
|
possibleSpawnLocations.Add(point); |
|
|
|
} |
|
|
@ -50,14 +52,21 @@ public class blockSpawn : MonoBehaviour |
|
|
|
|
|
|
|
//pick a random value from those available, checks the location
|
|
|
|
//then removes it to remove the possibility of duplicates
|
|
|
|
while(spawnNumber > 0) |
|
|
|
//Debug.Log(possibleSpawnLocations.Count);
|
|
|
|
if(possibleSpawnLocations.Count > 0) |
|
|
|
{ |
|
|
|
int choice = Random.Range(0, possibleSpawnLocations.Count - 1); |
|
|
|
bool spawned = checkLocation(possibleSpawnLocations[choice].transform.position); |
|
|
|
if (spawned == true) |
|
|
|
while (spawnNumber > 0) |
|
|
|
{ |
|
|
|
possibleSpawnLocations.RemoveAt(choice); |
|
|
|
spawnNumber--; |
|
|
|
if(possibleSpawnLocations.Count > 0){ |
|
|
|
int choice = Random.Range(0, possibleSpawnLocations.Count - 1); |
|
|
|
bool spawned = checkLocation(possibleSpawnLocations[choice].transform.position); |
|
|
|
if (spawned == true) |
|
|
|
{ |
|
|
|
possibleSpawnLocations.RemoveAt(choice); |
|
|
|
spawnNumber--; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
spawnNumber = 2; |
|
|
@ -123,6 +132,6 @@ public class blockSpawn : MonoBehaviour |
|
|
|
|
|
|
|
int number = Random.Range(0, listtoUse.Length-1); |
|
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.element = listtoUse[number].element; |
|
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.Count = listtoUse[number].Count; |
|
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.Count = 1; |
|
|
|
} |
|
|
|
} |