Make Real-time multiplayer games using Unity3D

unity logo Make Real time multiplayer games using Unity3Dappwarp Make Real time multiplayer games using Unity3DUnity3D is a popular cross-platform game engine for building sophisticated 3D games. Using AppWarp, developers can now add realtime communication in their Unity3D games to build beautiful, rich and engaging multiplayer games. The great thing is that developers can do this without any server side code or socket level programming as all the communication is managed by AppWarp SDK and cloud.

To help you get started, we have created a sample project that illustrates how to get the pieces together and set up the basic code required. You can watch this video describing how to get the sample running.

Complete source code for the sample is also available in our Git Repo. Below are some of the relevant code snippets. To initialize the SDK. You need to pass in your Api key and Secret key.

1
WarpClient.initialize(apiKey,secretKey);

Now create and add a Listener which implements the relevant WarpClient callback interfaces and connect with the server.

1
2
3
4
Listener warpLayer = new Listener();
WarpClient.GetInstance().AddConnectionRequestListener(warpLayer);
WarpClient.GetInstance().AddNotificationListener(warpLayer);
WarpClient.GetInstance().AddRoomRequestListener(warpLayer);

Now simply call connect to establish your connection with the server.

1
WarpClient.GetInstance().Connect();

Once your connection is established and authenticated, you will simply join a room and subscribe it to receive its notifications.

1
2
WarpClient.GetInstance().SubscribeRoom(roomid);
WarpClient.GetInstance().JoinRoom(roomid);

After you have joined the room, you can start sending your user’s coordinates to other users in the room. In this example we will use our Chat api to do that

1
2
string json = "{\"x\":\""+transform.position.x+"\",\"y\":\""+transform.position.y+"\",\"z\":\""+transform.position.z+"\"}";
WarpClient.GetInstance().SendChat(msg);

Once the remote player also joins, you will start receiving messages from it. Handle them and move the cylinder representing it

1
2
3
4
5
6
7
8
9
public void onChatReceived (ChatEvent eventObj)
{
    Log(eventObj.getSender() + " sent " + eventObj.getMessage());
    SimpleJSON.JSONNode msg =  SimpleJSON.JSON.Parse(eventObj.getMessage());
    if(eventObj.getSender() != id)
    {
        appwarp.movePlayer(msg["x"].AsFloat,msg["y"].AsFloat,msg["z"].AsFloat);
    }
}

And thats it! Simply build and run your Unity3D application on two different endpoints and you will be able to see each other’s endpoint movements in realtime (a simple white cylinder).

appwarp unity multiplayer Make Real time multiplayer games using Unity3D

You can also add leader boards, reward management and push notifications to your game by importing the App42 Unity asset in to your project. For a complete list of backend APIs available, visit the App42 page.

Instructions on downloading this sample and getting your API Key, Secret Key and RoomId can be found in our GIT repo here. To learn more about AppWarp, check out the product overview.



3893cb46 e00d 48a3 ab37 ed895529743d Make Real time multiplayer games using Unity3D








e8253fa5 df47 47fa 9620 f85e4e0e33a0 Make Real time multiplayer games using Unity3D



twitter Make Real time multiplayer games using Unity3Dfacebook Make Real time multiplayer games using Unity3Dgoogle Make Real time multiplayer games using Unity3Dlinkedin Make Real time multiplayer games using Unity3Dpinterest Make Real time multiplayer games using Unity3Dreddit Make Real time multiplayer games using Unity3Dstumbleupon Make Real time multiplayer games using Unity3Dtumblr Make Real time multiplayer games using Unity3D

Leave a Reply

Your email address will not be published. Required fields are marked *


7 − four =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>