Unity Spawn Manager Code


SUBMITTED BY: Guest

DATE: Nov. 11, 2013, 9:01 p.m.

FORMAT: Text only

SIZE: 985 Bytes

HITS: 976

  1. // Run through the list, spawn character
  2. public void SpawnEverything()
  3. {
  4. Debug.Log("Spawning " + spawnPointManager.spawnPoints.Count + " players");
  5. // Cycle through spawn point list
  6. foreach (GameObject spawnPointObj in spawnPointManager.spawnPoints)
  7. {
  8. // Access spawn point component script
  9. SpawnPoint spawnPoint = spawnPointObj.GetComponent<SpawnPoint>();
  10. // Decide to spawn player or NPC
  11. if(spawnPoint.isNPC)
  12. SpawnNPC(spawnPoint);
  13. else
  14. SpawnPlayer(spawnPoint);
  15. }
  16. Debug.Log("Everything Spawned!");
  17. }
  18. public void SpawnPlayer(SpawnPoint spawn)
  19. {
  20. Network.Instantiate(playerPrefab, spawn.transform.position, spawn.transform.rotation, 0);
  21. Debug.Log("Player Spawned");
  22. }
  23. public void SpawnNPC(SpawnPoint spawn)
  24. {
  25. Network.Instantiate(npcPrefab, spawn.transform.position, spawn.transform.rotation, 0);
  26. Debug.Log("NPC Spawned");
  27. }

comments powered by Disqus