26 lines
857 B
C#
26 lines
857 B
C#
using System.Collections.Generic;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
namespace DefaultNamespace
|
|
{
|
|
public class GameManager : NetworkBehaviour
|
|
{
|
|
[SerializeField] private NetworkObject playerPrefab;
|
|
[SerializeField] private Transform[] startPositions;
|
|
|
|
private int _currentStartPositionIndex = 0;
|
|
|
|
protected override void OnInSceneObjectsSpawned()
|
|
{
|
|
if (!IsServer) return;
|
|
|
|
foreach (KeyValuePair<ulong, NetworkClient> client in NetworkManager.ConnectedClients)
|
|
{
|
|
Transform position = startPositions[_currentStartPositionIndex++ % startPositions.Length];
|
|
NetworkObject player = Instantiate(playerPrefab, position.position, position.rotation);
|
|
player.SpawnAsPlayerObject(client.Key);
|
|
}
|
|
}
|
|
}
|
|
} |