Worker 네트워크 동기화

This commit is contained in:
2026-02-02 12:59:56 +09:00
parent b5f8943bcc
commit a0cb8499b0
5 changed files with 159 additions and 31 deletions

View File

@@ -94,7 +94,7 @@ namespace Northbound
GameObject workerObj = Instantiate(workerPrefab, spawnPosition, Quaternion.identity);
NetworkObject workerNetObj = workerObj.GetComponent<NetworkObject>();
if (workerNetObj == null)
{
Debug.LogError("[WorkerSpawner] Worker prefab must have NetworkObject component");
@@ -102,18 +102,19 @@ namespace Northbound
return;
}
workerNetObj.Spawn();
_lastSpawnTime = Time.time;
_workerCount.Value++;
// IMPORTANT: Spawn as server-owned so server can modify worker's NetworkVariables
workerNetObj.Spawn();
_lastSpawnTime = Time.time;
_workerCount.Value++;
ShowSpawnEffectClientRpc(spawnPosition);
ShowSpawnEffectClientRpc(spawnPosition);
Debug.Log($"[WorkerSpawner] 워커 생성됨 (총 워커: {_workerCount.Value}/{maxWorkers})");
Debug.Log($"[WorkerSpawner] Worker spawned (server-owned) and assigned to player {playerId} (Total: {_workerCount.Value}/{maxWorkers})");
ScheduleWorkerAssignment(playerId, workerNetObj.NetworkObjectId);
}
ScheduleWorkerAssignment(playerId, workerNetObj.NetworkObjectId);
}
private void ScheduleWorkerAssignment(ulong playerId, ulong workerNetObjectId)
private void ScheduleWorkerAssignment(ulong playerId, ulong workerNetObjectId)
{
StartCoroutine(AssignWorkerAfterFrame(playerId, workerNetObjectId));
}