Update ServerCharacter.cs

dev-hazimBeforeMerge
Hazim Bin Ijaz 4 weeks ago
parent 68c64b1293
commit 71bc52f824

@ -192,35 +192,86 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
} }
} }
public void SetAsCrow(bool status) public void SetAsCrow(bool status)
{ {
IsCrow = status; if (IsServer)
{
IsCrow = status; // Update on the server
UpdateCrowStatusClientRpc(status); // Notify all clients
}
else
{
Debug.LogWarning("SetAsCrow should only be called on the server.");
}
}
[ClientRpc]
private void UpdateCrowStatusClientRpc(bool status)
{
IsCrow = status; // Update the value for all clients
} }
public void SetTargetPlatform(int platformId) public void SetTargetPlatform(int platformId)
{ {
TargetPlatformId = platformId; if (IsServer)
{
TargetPlatformId = platformId; // Update on the server
UpdateTargetPlatformClientRpc(platformId); // Notify all clients
}
else
{
Debug.LogWarning("SetTargetPlatform should only be called on the server.");
}
} }
public void ClearTargetPlatform() public void ClearTargetPlatform()
{ {
TargetPlatformId = null; if (IsServer)
{
TargetPlatformId = null; // Update on the server
UpdateTargetPlatformClientRpc(-1); // Notify all clients (use -1 to indicate no platform)
}
else
{
Debug.LogWarning("ClearTargetPlatform should only be called on the server.");
}
}
[ClientRpc]
private void UpdateTargetPlatformClientRpc(int platformId)
{
TargetPlatformId = platformId != -1 ? platformId : (int?)null; // Update the value for all clients
} }
public void OnArrivalOnPlatform() public void OnArrivalOnPlatform()
{ {
ClearTargetPlatform(); ClearTargetPlatform();
SetOnPlatform(true); SetOnPlatform(true); // Automatically syncs to all clients
} }
public void OnLeavingPlatform() public void OnLeavingPlatform()
{ {
SetOnPlatform(false); SetOnPlatform(false); // Automatically syncs to all clients
} }
public void SetOnPlatform(bool status) public void SetOnPlatform(bool status)
{ {
IsOnAPlatform = status; if (IsServer)
{
IsOnAPlatform = status; // Update on the server
UpdatePlatformStatusClientRpc(status); // Notify all clients
}
else
{
Debug.LogWarning("SetOnPlatform should only be called on the server.");
}
}
[ClientRpc]
private void UpdatePlatformStatusClientRpc(bool status)
{
IsOnAPlatform = status; // Update the value for all clients
} }

Loading…
Cancel
Save