You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HighGroundRoyaleNetcode/Assets/Scripts/Gameplay/PlayerScoreComponent.cs

53 lines
1.8 KiB
C#

using UnityEngine;
using Unity.Netcode;
1 month ago
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
public class PlayerScoreComponent : NetworkBehaviour
{
public int CurrentScore { get; private set; }
1 month ago
public ServerCharacter serverCharacter;
public int m_index;
public PlayerItem playerItem;
public override void OnNetworkSpawn()
{
//if (IsOwner && IsClient)
//{
// Debug.Log($"[PlayerScoreComponent] Requesting score initialization for Player {OwnerClientId}");
// ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId,serverCharacter.uIStateDisplayHandler.m_UIState.playerName);
//}
//// For the server player (host), ensure the PlayerScoreComponent is registered properly
//if (IsServer && OwnerClientId == NetworkManager.Singleton.LocalClientId)
//{
// ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId, serverCharacter.uIStateDisplayHandler.m_UIState.playerName);
//}
if(IsOwner)
{
Debug.Log($"[PlayerScoreComponent] Requesting score initialization for Player {OwnerClientId}");
1 month ago
ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId, serverCharacter.uIStateDisplayHandler.m_UIState.playerName);
}
serverCharacter =GetComponent<ServerCharacter>();
}
public void UpdateScore(int newScore)
{
CurrentScore = newScore;
Debug.Log($"[PlayerScoreComponent] Player {OwnerClientId} score updated to {newScore}.");
UpdateScoreUI();
}
private void UpdateScoreUI()
{
// Update the player's score display in the UI.
Debug.Log($"[PlayerScoreComponent] Updated score UI for Player {OwnerClientId}: {CurrentScore}");
}
//private void OnDestroy()
//{
// Destroy(playerItem.gameObject);
//}
}