Learn how to:
Requirements:
One of my Unity projects utilizes UNet which is a low level multiplayer API which is now deprecated. I needed a good networking solution that supports basic server-client communication and data transport. In search for a replacement, I quickly found Mirror.
Mirror Logo. Image source
Good reviews and seems like it’s beginner friendly. Image source
Until now it seems to work really well. Everything is good to understand after using a beginner tutorial and the documentation. — Acdia, Unity Asset Store
One way I experimented with Mirror to make sure it fits my application’s needs was to create a chat system. I found several helpful tutorials online for setting up a chat box and network manager. Here I will aggregate those tutorials and show a comprehensive source for creating a chat system in Unity. This tutorial assumes that you have already installed Unity (preferably updated to the latest version or 2018.4 LTS and higher for compatibility with Mirror).
The first step is to install Mirror. It is a Unity Package so installation is very simple. Go to the Mirror page on Unity asset store (create a Unity account if you haven’t) and click on “Add to My Assets”. Follow the installation process to open with Unity, download the package, and install into your app. In order for the Mirror _GameObjects _to show up, restart Unity.
Once you have restarted Unity, create an Empty GameObject and name it “NetworkManager”. This will contain Mirror components needed to establish our server and player connections. To NetworkManager, add a _NetworkManager _component (which will also add Telepathy Transport) and a NetworkManagerHUD. Leave all fields as their presets for now.
If you are developing a game, the client could be an object or character in your game. When players join the game, they are represented as that object or character. Since we are creating a standalone chat, any of the default shapes should work. I chose a cube, but feel free to pick one of the other standard 2D or 3D shapes. Add a _Cube _object to the scene.
#chat #unity #c-sharp-programming