// Spawn a projectile (Should be done with object pooling) public Projectile SpawnProjectile(byte prefabIndex) { GameObject prefab = GameData.instance.projectilePrefabs[prefabIndex]; Projectile projectile = Instantiate(prefab).GetComponent <Projectile>(); projectiles.Add(projectile); colliderIdWithProjectiles.Add(projectile.collider.GetInstanceID(), projectile); return(projectile); }
// Spawn a selector private PlayerSelector SpawnPlayerSelector(byte id) { PlayerSelector selector = Instantiate(selectorPrefab, selectorParent.GetChild(0)).GetComponent <PlayerSelector>(); selector.AssignId(id); selector.parent = selectorParent; selectorList?.Add(selector); return(selector); }
private void Awake() { MultiplayerManager.PacketEvt += PacketHandler; enemies = new ObjSyncList <BaseEnemy>(null); // Assign ids to the objects BaseEnemy[] enemyList = FindObjectsOfType <BaseEnemy>(); byte i = 3; foreach (BaseEnemy enemy in enemyList) { enemy.AssignId(i); enemies.Add(enemy); i++; } }
private void Awake() { MultiplayerManager.PacketEvt += PacketHandler; interactables = new ObjSyncList <Interactable>(null); // Assign ids to the objects Interactable[] interactableList = FindObjectsOfType <Interactable>(); byte i = 0; foreach (Interactable interactable in interactableList) { interactable.AssignId(i); interactables.Add(interactable); i++; } }
public void OnEnable() { MultiplayerManager.PacketEvt += RecieveConnection; PhysicsManager.PhysicsEvt += PhysicsHandler; objects = new ObjSyncList <PhysicsObject>(null); movedObjList = new ObjSyncList <PhysicsObject>(null); // Assign ids to the objects PhysicsObject[] objList = FindObjectsOfType <PhysicsObject>(); byte i = 0; foreach (PhysicsObject obj in objList) { obj.AssignId(i); objects.Add(obj); i++; } }
public void SpawnAllPlayer() { cachedSelectors.TryGetValue(MultiplayerManager.LocalId, out int type); BasePlayer localPlayer = SpawnPlayer((PlayerType)type, MultiplayerManager.LocalId); players = new ObjSyncList <BasePlayer>(localPlayer); Camera.main.transform.SetParent(localPlayer.transform, false); for (byte i = 0; i < cachedSelectors.Count; i++) { if (i != MultiplayerManager.LocalId) { cachedSelectors.TryGetValue(i, out int otherType); players.Add(SpawnPlayer((PlayerType)otherType, i)); } } cachedSelectors.Clear(); MultiplayerManager.PacketEvt += RecieveConnection; MultiplayerManager.DisconnectEvt += Disconnection; }