using System.Collections; using System.Collections.Generic; using UnityEngine; using Mirror; using Unity.Mathematics; public class GameManager : NetworkBehaviour { public Transform spawnPointsParent; public GameObject enemyPrefab; public Transform LootSpawnPointsParent; public Transform spawnPointsPlayer; public static GameManager instance; public List lootDatas; private void Awake() { instance = this; } void Start(){ if(isServer){ for(int i = 0; i< spawnPointsParent.childCount; i++){ GameObject newEnemy = Instantiate(enemyPrefab , spawnPointsParent.GetChild(i).position, Quaternion.identity); NetworkServer.Spawn(newEnemy); // newEnemy.transform.position = spawnPointsParent.GetChild(i).position; } for(int i=0; i < LootSpawnPointsParent.childCount; i++){ GameObject selectedLootPrefab = lootDatas[0].prefab; foreach(LootData loot in lootDatas){ int probCal = UnityEngine.Random.Range(0,100); if(probCal < loot.spawnProbability){ selectedLootPrefab = loot.prefab; break; } } GameObject newLoot = Instantiate(selectedLootPrefab, LootSpawnPointsParent.GetChild(i).position, Quaternion.identity); NetworkServer.Spawn(newLoot); } } } public void SpawnPickup(string type, Vector3 position){ foreach(LootData loot in lootDatas){ if(loot.type == type){ GameObject newLoot = Instantiate(loot.prefab, position, Quaternion.identity); NetworkServer.Spawn(newLoot); return; } } Debug.LogError("Couldn't find loot data for " + type); } }