Hey, Riku here!
In the blog before last, I showed you how to set up Visual Studio as Unity’s default code editor so that you can easily work with scripts in Unity!
In the video Practical Guide Ep. 3 | Synchronizing the Arrow Effects and Developing the Chat System, we developed a way to make effects appear when an arrow hits another player and develop a chat system.
In this blog, I will go over in detail how I developed a chat system using a technique called RPCs.
|Contents
|Developing a Chat System
We are going to develop a chat system using RPCs.
You can learn more about RPCs in Riku’s Question Corner!
There are 2 things we will need to display on the screen this time, the chat log and the chat speech bubbles.
Display Logs After Sending Messages in Chat
In the Chat.cs script found in my sample project, we are going to set up a function and call it using an RPC.
In addition, you can use the Unity standard “InputField” function for inputting strings such as chat strings.
Check out the full video Practical Guide Ep. 3 | Synchronizing the Arrow Effects and Developing the Chat System to learn how to actually code this!
Displaying the Speech Bubbles
Speech bubbles should be displayed above the character who sends a message in chat. Therefore, we must determine which character sent a message based on the owner of the respective character object.
StrixRpcContext has a parameter called SenderUid which points to the owner of the object. If the ownerUid in the strixReplicator matches the SenderUid, it determines that that is the character who sent the RPC.
This completes the development of our chat!
|Riku’s Question Corner: “What are RPCs?”
Riku:
“Hey, Apollo, what do RPC in STRIX do?”
Apollo:
“Well, let me explain about RPCs!
RPC stands for ‘Remote Procedure Call’.
By using RPCs, you can make other players perform the same action you’ve done via the network.
For example, you can make your character on another player’s screen do a waving emote.
RPCs can also be used to deal with players taking damage where you can reduce the health bar of a character once they’ve been hit with a projectile.
It can also be used in developing a chat system.
Moreover, with Strix Cloud, you can easily register RPCs just by simply adding an attribute.
In other words, you can easily add RPC functionality without the need to extend your program!”
Let’s Create an Online Game! Ep. 6 | Synchronizing Animations (4:32)