add unity project for networking
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user