업그레이드 데이터 입력 로직 및 기능 추가
캐릭터 스탯을 PlayerStats 컴포넌트에서 모아서 관리하도록 변경 코드에서도 마찬가지
This commit is contained in:
@@ -9,15 +9,11 @@ using Northbound;
|
||||
public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageable
|
||||
{
|
||||
[Header("Movement Settings")]
|
||||
public float moveSpeed = 5f;
|
||||
public float rotationSpeed = 10f;
|
||||
|
||||
[Header("Team Settings")]
|
||||
[SerializeField] private TeamType initialTeam = TeamType.Player;
|
||||
|
||||
[Header("Health Settings")]
|
||||
[SerializeField] private int maxHealth = 100;
|
||||
|
||||
[Header("Visual Effects")]
|
||||
[SerializeField] private GameObject damageEffectPrefab;
|
||||
[SerializeField] private GameObject deathEffectPrefab;
|
||||
@@ -50,8 +46,11 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl
|
||||
private PlayerInputActions _inputActions;
|
||||
private Animator _animator;
|
||||
private NetworkAnimator _networkAnimator;
|
||||
private PlayerStats _playerStats;
|
||||
|
||||
// 이 플레이어가 로컬 플레이어인지 확인
|
||||
|
||||
|
||||
public bool IsLocalPlayer => _ownerPlayerId.Value == NetworkManager.Singleton.LocalClientId;
|
||||
|
||||
public ulong OwnerPlayerId => _ownerPlayerId.Value;
|
||||
@@ -64,6 +63,7 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl
|
||||
_controller = GetComponent<CharacterController>();
|
||||
_animator = GetComponent<Animator>();
|
||||
_networkAnimator = GetComponent<NetworkAnimator>();
|
||||
_playerStats = GetComponent<PlayerStats>();
|
||||
}
|
||||
|
||||
public override void OnNetworkSpawn()
|
||||
@@ -80,7 +80,7 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl
|
||||
|
||||
if (_currentHealth.Value == 0)
|
||||
{
|
||||
_currentHealth.Value = maxHealth;
|
||||
_currentHealth.Value = GetMaxHealth();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl
|
||||
|
||||
if (_controller != null)
|
||||
{
|
||||
_controller.Move(move * moveSpeed * Time.deltaTime);
|
||||
_controller.Move(move * (_playerStats?.GetMoveSpeed() ?? 5f) * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -376,7 +376,7 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl
|
||||
if (!IsServer) return;
|
||||
|
||||
// 체력 회복
|
||||
_currentHealth.Value = maxHealth;
|
||||
_currentHealth.Value = GetMaxHealth();
|
||||
|
||||
// 스폰 포인트로 이동
|
||||
var spawnPoints = FindObjectsByType<PlayerSpawnPoint>(FindObjectsSortMode.None);
|
||||
@@ -423,11 +423,12 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl
|
||||
|
||||
public int GetCurrentHealth() => _currentHealth.Value;
|
||||
|
||||
public int GetMaxHealth() => maxHealth;
|
||||
public int GetMaxHealth() => _playerStats?.GetMaxHp() ?? 100;
|
||||
|
||||
public float GetHealthPercentage()
|
||||
{
|
||||
return maxHealth > 0 ? (float)_currentHealth.Value / maxHealth : 0f;
|
||||
int max = GetMaxHealth();
|
||||
return max > 0 ? (float)_currentHealth.Value / max : 0f;
|
||||
}
|
||||
|
||||
public bool IsDead() => _currentHealth.Value <= 0;
|
||||
@@ -436,7 +437,7 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl
|
||||
{
|
||||
if (!IsServer) return;
|
||||
|
||||
int healAmount = Mathf.Min(amount, maxHealth - _currentHealth.Value);
|
||||
int healAmount = Mathf.Min(amount, GetMaxHealth() - _currentHealth.Value);
|
||||
_currentHealth.Value += healAmount;
|
||||
}
|
||||
|
||||
@@ -459,13 +460,13 @@ public class NetworkPlayerController : NetworkBehaviour, ITeamMember, IDamageabl
|
||||
{
|
||||
string teamName = TeamManager.GetTeamName(_team.Value);
|
||||
UnityEditor.Handles.Label(transform.position + Vector3.up * 3f,
|
||||
$"Player: {gameObject.name}\nTeam: {teamName}\nHP: {_currentHealth.Value}/{maxHealth}");
|
||||
$"Player: {gameObject.name}\nTeam: {teamName}\nHP: {_currentHealth.Value}/{GetMaxHealth()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
string teamName = TeamManager.GetTeamName(initialTeam);
|
||||
UnityEditor.Handles.Label(transform.position + Vector3.up * 3f,
|
||||
$"Player: {gameObject.name}\nTeam: {teamName}\nHP: {maxHealth}/{maxHealth}");
|
||||
$"Player: {gameObject.name}\nTeam: {teamName}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user