EnemyPortal이 작동하지 않는 문제 수정
Network 환경 대응
This commit is contained in:
@@ -4,42 +4,53 @@ using System.Collections.Generic;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyPortal : NetworkBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class MonsterEntry
|
||||
public class EnemyPortal : NetworkBehaviour
|
||||
{
|
||||
public GameObject prefab;
|
||||
}
|
||||
[System.Serializable]
|
||||
public class MonsterEntry
|
||||
{
|
||||
public GameObject prefab;
|
||||
}
|
||||
|
||||
[Header("Spawn Settings")]
|
||||
[Tooltip("몬스터 프리팹 목록 (Editor에서 자동 로드 가능)")]
|
||||
[SerializeField] private List<MonsterEntry> monsterEntries = new();
|
||||
[Header("Spawn Settings")]
|
||||
[Tooltip("몬스터 프리팹 목록 (Editor에서 자동 로드 가능)")]
|
||||
[SerializeField] private List<MonsterEntry> monsterEntries = new();
|
||||
|
||||
[Header("Cost Settings")]
|
||||
[Tooltip("시간당 코스트 시작 값")]
|
||||
[SerializeField] private float initialCost = 4f;
|
||||
[Tooltip("사이클마다 코스트 증가율 (%)")]
|
||||
[SerializeField] private float costIncreaseRate = 10f;
|
||||
[Header("Cost Settings")]
|
||||
[Tooltip("시간당 코스트 시작 값")]
|
||||
[SerializeField] private float initialCost = 4f;
|
||||
[Tooltip("사이클마다 코스트 증가율 (%)")]
|
||||
[SerializeField] private float costIncreaseRate = 10f;
|
||||
|
||||
private float currentCost;
|
||||
private float currentCost;
|
||||
|
||||
void Start()
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
currentCost = initialCost;
|
||||
base.OnNetworkSpawn();
|
||||
GlobalTimer.Instance.OnCycleStart += OnCycleStart;
|
||||
}
|
||||
|
||||
private void OnCycleStart(int cycleNumber)
|
||||
{
|
||||
SpawnMonsters();
|
||||
IncreaseCost();
|
||||
}
|
||||
public override void OnNetworkDespawn()
|
||||
{
|
||||
GlobalTimer.Instance.OnCycleStart -= OnCycleStart;
|
||||
base.OnNetworkDespawn();
|
||||
}
|
||||
|
||||
private void SpawnMonsters()
|
||||
{
|
||||
float remainingCost = currentCost;
|
||||
int spawnedCount = 0;
|
||||
void Start()
|
||||
{
|
||||
currentCost = initialCost;
|
||||
}
|
||||
|
||||
private void OnCycleStart(int cycleNumber)
|
||||
{
|
||||
SpawnMonsters();
|
||||
IncreaseCost();
|
||||
}
|
||||
|
||||
private void SpawnMonsters()
|
||||
{
|
||||
float remainingCost = currentCost;
|
||||
int spawnedCount = 0;
|
||||
|
||||
while (remainingCost > 0 && monsterEntries.Count > 0)
|
||||
{
|
||||
@@ -129,21 +140,21 @@ public class EnemyPortal : NetworkBehaviour
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SpawnEnemy(GameObject prefab)
|
||||
{
|
||||
if (!IsServer) return;
|
||||
|
||||
GameObject enemy = Instantiate(prefab, transform);
|
||||
|
||||
if (enemy.GetComponent<FogOfWarVisibility>() == null)
|
||||
private void SpawnEnemy(GameObject prefab)
|
||||
{
|
||||
var visibility = enemy.AddComponent<FogOfWarVisibility>();
|
||||
visibility.showInExploredAreas = false;
|
||||
visibility.updateInterval = 0.2f;
|
||||
}
|
||||
if (!IsServer) return;
|
||||
|
||||
enemy.GetComponent<NetworkObject>().SpawnWithOwnership(NetworkManager.Singleton.LocalClientId);
|
||||
}
|
||||
GameObject enemy = Instantiate(prefab, transform);
|
||||
|
||||
if (enemy.GetComponent<FogOfWarVisibility>() == null)
|
||||
{
|
||||
var visibility = enemy.AddComponent<FogOfWarVisibility>();
|
||||
visibility.showInExploredAreas = false;
|
||||
visibility.updateInterval = 0.2f;
|
||||
}
|
||||
|
||||
enemy.GetComponent<NetworkObject>().SpawnWithOwnership(NetworkManager.Singleton.LocalClientId);
|
||||
}
|
||||
|
||||
private void IncreaseCost()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user