Hi guys I am used to the legacy networking so I used to use code like this:
netView.RPC("rpcName", Target);
[RPC]
void rpcName ()
{
//Do something
}
So how do I do that with the new Unity Networking?
Thanks!
Hi guys I am used to the legacy networking so I used to use code like this:
netView.RPC("rpcName", Target);
[RPC]
void rpcName ()
{
//Do something
}
So how do I do that with the new Unity Networking?
Thanks!
All the information you need is in the doc:
http://docs.unity3d.com/Manual/UNetActions.html
Thanks for the link. From what I can see RPCs are way easier to use is there a way I can use the old RPCs with the new Networking?
No you can’t mix old and new API. You have to change your code with Command and ClientRpc attribute.
In the old Unity Networking for a chat box you’d send an rpc to update the chatbox with the new message.
How do I do that with the new networking?
You have to send a Command to the server and the server have to send an Rpc to the clients.
For example:
// historic.
private List<string> m_chatMessages = new List<string>();
// function called somewhere when the player write a message in the chat box.
public void SendChatMessage(string message)
{
CmdAddChatMessage(message);
}
// function called on the server.
[Command]
private void CmdAddChatMessage(string message)
{
RpcAddChatMessage(message);
}
// function called on the clients
[ClientRpc]
private void RpcAddChatMessage(message)
{
m_chatMessages.Add(message);
}