Communicating
There are a variety of ways to send communications between server and clients.
using FishNet.Object;
using FishNet.Object.Synchronizing;
public class Player : NetworkBehaviour
{
private readonly SyncVar<int> _health = new SyncVar<int>(100);
public void StepOnLego()
{
if (!IsServerInitialized)
return;
_health. Value -= 10;
}
}using FishNet.Object;
public class Player : NetworkBehaviour
{
[ServerRpc]
private void UpdatePlayerName(string newName)
{
print($"Player {OwnerId} has updated their name to {newName}");
}
}using FishNet;
using UnityEngine;
public class ChatSystem : MonoBehaviour
{
public void SendChatMessage(string text)
{
ChatBroadcast msg = new ChatBroadcast()
{
Message = text,
FontColor = Color.white
};
InstanceFinder.ClientManager.Broadcast(msg);
}
}Last updated