Beispiel #1
0
    void Start()
    {
        io.On("connect", (SocketIOEvent e) => {
            Debug.Log("SocketIO connected");
            io.Emit("test-event1");

            TestObject t = new TestObject();
            t.test       = 123;
            t.test2      = "test1";

            io.Emit("test-event2", JsonUtility.ToJson(t));

            TestObject t2 = new TestObject();
            t2.test       = 1234;
            t2.test2      = "test2";

            io.Emit("test-event3", JsonUtility.ToJson(t2), (string data) => {
                Debug.Log(data);
            });
        });

        io.Connect();

        io.On("test-event", (SocketIOEvent e) => {
            Debug.Log(e.data);
        });
    }
    // The backend calls this function to open a socket connection.
    // Once this happens, the game starts.
    public void EstablishConnection()
    {
        io.ResetSettings();

        io.On("connect", (SocketIOEvent e) =>
        {
            Debug.Log("SocketIO Connected.");
        });

        io.Connect();

        io.On("world-init", (SocketIOEvent e) =>
        {
            Debug.Log("World init.");

            // So that the server knows that requests have started
            // being processed.
            io.Emit("client-ready", Convert.ToString(userId));

            Debug.Log("Emitted response.");
        });

        io.On("world-update", (SocketIOEvent e) =>
        {
            WorldUpdate(e.data);
        });
    }
Beispiel #3
0
    void Start()
    {
        Instance = this;
        io       = FindObjectOfType <SocketIOController>();

        io.On("connect", e =>
        {
            //We just connected to the socket server
            Debug.Log("Connected");
            io.Emit("vieweronline");
        });

        io.On("reset", e =>
        {
            SceneManager.LoadScene(0);
        });

        io.On("enroll", e =>
        {
            ScreenDetector.gameObject.SetActive(true);
            ScreenDetector.EnrollNewScreen(e);
        });

        io.Connect();
    }
Beispiel #4
0
    // The backend calls this function to open a socket connection.
    // Once this happens, the game starts.
    public void EstablishConnection()
    {
        io.Connect();


        io.On("connect", (SocketIOEvent e) =>
        {
            Debug.Log("SocketIO Connected.");
        });


        io.On("world-init", (SocketIOEvent e) =>
        {
            Debug.Log("World init.");

            // So that the server knows that requests have started
            // being processed.
            io.Emit("client-ready", Convert.ToString(currentAvatarID));

            Debug.Log("Emitted response for the server for world initialisation.");
        });

        io.On("game-state", (SocketIOEvent e) =>
        {
            if (e.data == "")
            {
                return;
            }
            NewGameState(e.data);
        });
    }
Beispiel #5
0
 public void ConnectedToServer()
 {
     socket.On("onConnection", OnConnection);
     socket.On("joinedToRoom", JoinedToRoom);
     socket.On("gameReady", GameReady);
     socket.Connect();
 }
Beispiel #6
0
    private void InitializeMessageHandlers()
    {
        socket.On("game-message", HandleGameMessageReceived); // handle the main events that happen in the game

        socket.On("open", OnOpenMessage);                     // handles message that confirms connection

        socket.On("boop", (_) => Debug.Log("boop received")); // console log when beep-boop message is received
    }
 public void ConnectedToServer()
 {
     socket.On("onConnection", OnConnection);
     socket.On("roomCreated", RoomCreated);
     socket.On("playerEnter", PlayerEnter);
     socket.On("playerReady", PlayerReady);
     socket.On("playerInput", PlayerInput);
     socket.Connect();
 }
Beispiel #8
0
 void Start()
 {
     io.Connect();
     io.On("connect", (SocketIOEvent e) => {
         socket_connected = true;
     });
     io.On("disconnect", (SocketIOEvent e) => {
         socket_connected = false;
     });
 }
Beispiel #9
0
    public void Start()
    {
        socket = gameObject.GetComponent <SocketIOController>();
        Debug.Log(socket);
        mapHandler     = GameObject.Find("Map").GetComponent <MapHandler>();
        playerMovement = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerMovement>();


        //Default socket messages

        socket.On("connect", SocketOpen);
        socket.On("open", SocketOpen);
        socket.On("ping", SocketPing);

        socket.On("error", SocketError);
        socket.On("close", SocketClose);

        //Custom socket messages
        socket.On("mapres", MapDataFromServer);
        socket.On("newmove", PositionDataFromServer);
        //socket.On("newtweet", TweetDataFromServer);

        socket.On("tweets", TweetDataFromServer);

        socket.On("win", WinDataFromServer);

        socket.Connect();
    }
Beispiel #10
0
    void Start()
    {
        //Server cost: https://glitch.com/edit/#!/relay-server
        //Web client: https://relay-server.glitch.me/
        //
        // Server Commands
        // -Client to Server
        // 💬join (roomKey)
        // 💬leave (roomKey)
        // 💬whoami ()
        // 💬whoslistening ()
        //
        // -Server to Client
        // 💬youare (socketKey)
        // 💬joined
        // 💬peerjoin (socketKey)
        // 💬peerdrop (socketKey)
        // 💬listeners ([{ room: "theRoomKey", sockets: ["123", ...] }, ...])


        //On Connected Event
        io.On("connect", e =>
        {
            Debug.Log("Socket connected");
            io.Emit("💬join", "\"exampleRoom\"");
        });

        //Event notification when this client joins a room on the relay
        io.On("💬joined", e =>
        {
            Debug.Log("Joined room: " + e.data);

            //Broadcast a message for relay
            io.Emit("appSpecificMessage", "\"Hello from Unity\""); //Note the enclosing double quotes. IO is actually expecting JSON values, so strings need to be quoted
        });

        //Event notification when we receive an app specific message
        io.On("appSpecificMessage", e =>
        {
            Debug.Log("Received appSpecificMessage: " + e.data);
        });

        //Actually initiate the connection to the server
        io.Connect();
    }
Beispiel #11
0
    private void EstablishSocketConnection()
    {
        io.Connect();

        io.On("connect", (SocketIOEvent e) =>
        {
            Debug.Log("SocketIO Connected.");
        });


        io.On("game-state", (SocketIOEvent e) =>
        {
            if (e.data == "")
            {
                return;
            }

            NewGameState(e.data);
        });
    }
    void Start()
    {
        sprite = GetComponent <SpriteRenderer>();


        io.On("connect", (SocketIOEvent e) => {
            Debug.Log("SocketIO connected");
            io.Emit("test-event1");

            TestObject t = new TestObject();
            t.test       = 123;
            t.test2      = "test1";

            io.Emit("test-event2", JsonUtility.ToJson(t));

            TestObject t2 = new TestObject();
            t2.test       = 1234;
            t2.test2      = "test2";

            io.Emit("test-event3", JsonUtility.ToJson(t2), (string data) => {
                Debug.Log(data);
            });
        });

        io.Connect();

        io.On("test-event", (SocketIOEvent e) => {
            Debug.Log(e.data);
            sprite.color = Color.blue;
        });

        io.On("register", (SocketIOEvent e) => {
            Debug.Log("CORA");
        });

        /*
         * io.On("keyword", (SocketIOEvent e) => {
         * Debug.Log("registered");
         * });
         */
    }
    void Start()
    {
        io.On("connect", onConnect);
        io.On("💬joined", onRoomJoined);
        io.On("💬youare", onYouAreMessageReceived);
        io.On("💬listeners", onListenersReceived);
        io.On("💬peerjoin", onPeerJoined);
        io.On("💬peerdrop", onPeerDropped);
        io.On("userPose", onUserPoseReceived);
        io.Connect();

        transmit();
    }
Beispiel #14
0
        void Start()
        {
            socket = GetComponent <SocketIOController>();

            socket.On("mothership", OnMothershipEmit);
            socket.On("session", OnSessionStarted);
            socket.On("open", OnConnected);
            socket.On("spawn", OnSpawned);
            socket.On("unspawn", OnUnspawned);
            socket.On("move", OnPlayerMovement);
            socket.On("enemy", OnEnemyMovement);

            socket.Connect();
        }
Beispiel #15
0
    //Network Initialization
    private void Start()
    {
        socket = GetComponent <SocketIOController>();
        socket.Connect();

        //Begin socket listening
        socket.On("register", OnRegister);
        socket.On("spawn", OnSpawned);
        socket.On("moved", OnMoved);
        socket.On("disconnected", OnDisconnected);
        socket.On("requestPosition", OnRequestPosition);
        socket.On("updatingPosition", OnUpdatingPosition);
        socket.On("attack", OnAttack);
        socket.On("face", OnFace);

        //Instantiate player list
        otherPlayers = new Dictionary <string, GameObject>();

        //TODO: Delete this, it's for testing only
        socket.On("test-event", (SocketIOEvent e) => {
            var purp   = block.GetComponent <SpriteRenderer>();
            purp.color = Color.blue;
        });
    }
    void Start()
	{
        Application.targetFrameRate = 60;

        socket = GetComponent<SocketIOController>();
        gameMenu = GetComponent<GameMenu>();

        //to switch quickly between local and online you can override the settings here
        if (GLITCH)
        {
            socket.settings.url = "yourglitchdomain.glitch.me";
            socket.settings.port = 0 ;
            socket.settings.sslEnabled = true;
        }
        else if (HEROKU)
        {
            socket.settings.url = "yourherokudomain.herokuapp.com";
            socket.settings.port = 5000;
            socket.settings.sslEnabled = true;
        }

        //connect to the server
        socket.Connect();

        Net.connected = false;
        
        //Listeners connecting socket events from the server and the functions below
        socket.On("socketConnect", OnSocketConnect);
        
        socket.On("nameError", OnNameError);
        
        //any player connected including me
        socket.On("playerJoin", OnPlayerJoin);

        //just connected, server sends me all the player info
        socket.On("addPlayerData", OnAddPlayerData);
        
        //another player disconnected
        socket.On("playerDisconnect", OnPlayerDisconnect);
        
        //a net object is instantiated
        socket.On("instantiate", OnNetInstantiate);

        //or destroyed
        socket.On("destroy", OnNetDestroy);

        //a net object position has changed
        socket.On("updateTransform", OnUpdateTransform);

        //a net object changed ownership
        socket.On("changeOwner", OnChangeOwner);

        //a net object changed type TEMPORARY, PRIVATE, SHARED... 
        socket.On("changeType", OnChangeType);
        
        //net variables changed
        socket.On("setVariables", OnSetVariables);

        //a net function has been called
        socket.On("netFunction", OnNetFunction);
        
        //the server changes the authority
        socket.On("setAuthority", OnSetAuthority);

        //a chat message arrives
        socket.On("message", OnMessage);
        
        //Net.cs is just a global class
        //every variable in there is visible from anywhere

        //initialize players
        Net.players = new Dictionary<string, Player>();
        //initialize net objects
        Net.objects = new Dictionary<string, NetObject>();
        
        //make a global reference to this script
        Net.manager = this;
        

        ServerMessage("Connecting to server...");

        Invoke("Timeout", 10);

    }//end start
        // Update is called once per frame
        // public override void Update()
        // {
        //     base.Update();
        // }
        private void SetupEvents()
        {
            // Initial connection will connect just once, even if console displays TWO logs.
            io.On("open", (e) => {
                Debug.Log("connection made to server");
            });

            io.On("register", (e) => {
                ClientID = new JSONObject(e.data)["id"].str;
                Debug.LogFormat("Our Client's Id is ({0})", ClientID);
            });

            io.On("spawn", (e) => {
                // handling all spawned players
                string id = new JSONObject(e.data)["id"].str;

                GameObject go      = Instantiate(playerGO, networkContainer);
                go.name            = string.Format("Player ({0})", id);
                NetworkIdentity ni = go.GetComponent <NetworkIdentity>();
                ni.SetControllerID(id);
                ni.SetSocketReference(io.socketIO);
                serverObjects.Add(id, ni);
            });

            io.On("disconnected", (e) => {
                string id = new JSONObject(e.data)["id"].str;
                Debug.Log("player disconnected");
                GameObject go = serverObjects[id].gameObject;
                Destroy(go); // remove GO from game
                serverObjects.Remove(id);
            });

            io.On("updateRotation", (e) => {
                JSONObject data    = new JSONObject(e.data);
                string id          = data["id"].ToString().RemoveQuotes();
                float weaponRot    = data["weaponRotation"].f;
                bool flipped       = data["playerFlipped"].b;
                NetworkIdentity ni = serverObjects[id];
                // Debug.Log("updating other rotations");
                ni.GetComponent <PlayerManager>().SetWeaponRotation(weaponRot);
            });

            io.On("updatePosition", (e) => {
                JSONObject data       = new JSONObject(e.data);
                string id             = data["id"].ToString().RemoveQuotes();
                float x               = data["position"]["x"].f;
                float y               = data["position"]["y"].f;
                NetworkIdentity ni    = serverObjects[id];
                ni.transform.position = new Vector3(x, y, 0);
            });

            io.On("serverSpawn", (e) => {
                JSONObject data = new JSONObject(e.data);
                string name     = data["name"].str;
                string id       = data["id"].ToString().RemoveQuotes();
                float x         = data["position"]["x"].f;
                float y         = data["position"]["y"].f;
                if (!serverObjects.ContainsKey(id))
                {
                    // Debug.LogFormat("Server wants to spawn '{0}'", name);
                    ServerObjectData sod           = serverSpawnables.GetObjectByName(name);
                    var spawnObject                = Instantiate(sod.Prefab, networkContainer);
                    spawnObject.transform.position = new Vector3(x, y, 0);
                    NetworkIdentity ni             = spawnObject.GetComponent <NetworkIdentity>();
                    ni.SetControllerID(id);
                    ni.SetSocketReference(io.socketIO);

                    // if projectile apply direction as well
                    if (name == "Arrow_Regular")
                    {
                        float directionX = data["direction"]["x"].f;
                        float directionY = data["direction"]["y"].f;
                        string activator = data["activator"].ToString().RemoveQuotes();
                        float speed      = data["speed"].f;

                        float rot = Mathf.Atan2(directionY, directionX) * Mathf.Rad2Deg;
                        Vector3 currentRotation        = new Vector3(0, 0, rot + 180);
                        spawnObject.transform.rotation = Quaternion.Euler(currentRotation);

                        WhoActivatedMe whoActivatedMe = spawnObject.GetComponent <WhoActivatedMe>();
                        whoActivatedMe.SetActivator(activator);

                        Projectile projectile = spawnObject.GetComponent <Projectile>();
                        projectile.Direction  = new Vector2(directionX, directionY);
                        projectile.Speed      = speed;
                    }
                    serverObjects.Add(id, ni);
                }
            });
            io.On("serverDespawn", (e) => {
                string id          = new JSONObject(e.data)["id"].str;
                NetworkIdentity ni = serverObjects[id];
                serverObjects.Remove(id);
                Destroy(ni.gameObject);
            });
            io.On("playerDied", (e) => {
                string id          = new JSONObject(e.data)["id"].str;
                NetworkIdentity ni = serverObjects[id];
                ni.gameObject.SetActive(false);
            });
            io.On("playerRespawn", (e) => {
                JSONObject data       = new JSONObject(e.data);
                string id             = data["id"].ToString().RemoveQuotes();
                float x               = data["position"]["x"].f;
                float y               = data["position"]["y"].f;
                NetworkIdentity ni    = serverObjects[id];
                ni.transform.position = new Vector3(x, y, 0);
                ni.gameObject.SetActive(true);
            });
            io.On("loadGame", (e) => {
                SceneManagementManager.Instance.LoadLevel(levelName: SceneList.LEVEL, onLevelLoaded: (levelName) => {
                    SceneManagementManager.Instance.UnLoadLevel(SceneList.MAIN_MENU);
                });
            });
        }
Beispiel #18
0
    void Start()
    {
        if (isBotClient && isBotOrc)
        {
            botsetup(PlayerFaction.Orc);
        }
        else if (isBotClient && !isBotOrc)
        {
            botsetup(PlayerFaction.Warrior);
        }

        // socket = GetComponent<SocketIOControllerWeb>();
        socket = GetComponent <SocketIOController>();
        socket.Connect();
        socket.On("open", OnConnected);
        socket.On("register", OnRegister);
        socket.On("zone_data", OnInitialZoneData);
        socket.On("name", OnName);
        socket.On("spawn", OnSpawn);
        socket.On("move", OnMove);
        socket.On("jump", OnJump);
        socket.On("disconnected", OnDisconnected);
        socket.On("damage", OnDamage);
        socket.On("died", OnDeath);
        socket.On("respawn1", OnRespawnRequest);
        socket.On("respawn2", OnRespawn);
        socket.On("attack_animation", OnAttackAnimation);
        socket.On("reset_animation", OnResetAnimation);
        socket.On("score", OnScore);
        socket.On("chat", OnChat);
        socket.On("zone_update", OnZoneUpdate);
        socket.On("ai_animation", OnAIPlayAnimation);
        socket.On("disconnect", delegate { Application.Quit(); });
    }
    void Start()
    {
    #if UNITY_WEBGL
        string url  = "battle-nodez.herokuapp.com";
        int    port = 80;


        //string absoluteURL = Application.absoluteURL;
        //if(absoluteURL.Length > 0 && absoluteURL.IndexOf("herokuapp") == -1) {
        //    url = "battlenodes.net";
        //    port = 8080;
        //}

        Debug.Log("URL" + url);
        Debug.Log("Port" + port);

        io.settings.url  = url;
        io.settings.port = port;
    #endif

        Debug.Log("SocketIO connected");
        io.On("connect", this.HandleConnect);
        io.On("identity", this.HandleIdentity);
        io.On("allplayersready", this.HandleAllPlayersReady);
        io.On("gameinfo", this.HandleGameInfo);

        io.On("playerMove", this.HandlePlayerMove);
        io.On("turretRotate", this.HandleTurretRotate);
        io.On("attack", this.HandleAttack);
        io.On("damage", this.HandleDamage);

        io.On("playerDefeated", this.HandlePlayerDefeated);
        io.On("gameOver", this.HandleGameOver);
        // io.On("gameover", this.HandleGameOver);

        io.On("playerLeft", this.HandlePlayerLeft);

        io.Connect();
    }
Beispiel #20
0
        // Import the JSLib as following. Make sure the
        // names match with the JSLib file we've just created.

        private void setupEvents()
        {
            io.On("connect", (e) => {
                io.Emit("addUnityUser");
            });

            io.On("register", (e) => {
                Player player = JsonUtility.FromJson <Player>(e.data);
                ClientId      = player.id;
                Debug.LogFormat("pur client Id", ClientId);
            });

            io.On("spawn", (SocketIOEvent e) => {
                Player newPlayer   = JsonUtility.FromJson <Player>(e.data);
                GameObject go      = Instantiate(playerPrefab, networkContainer);
                go.name            = string.Format("Player ({0})", newPlayer.id);
                NetworkIdentity ni = go.GetComponent <NetworkIdentity>();
                ni.SetControllerId(newPlayer.id);
                ni.SetSocketRefrence(io);
                serverObjects.Add(newPlayer.id, ni);
            });

            io.On("updatePosition", (e) => {
                Player player         = JsonUtility.FromJson <Player>(e.data);
                string id             = player.id;
                float x               = player.position.x;
                float y               = player.position.y;
                NetworkIdentity ni    = serverObjects[id];
                ni.transform.position = new Vector3(x, y, 0);
            });

            // gets called if someone is playing on a difrent tab or browser
            io.On("duplicatePlayer", (e) => {
                Debug.Log("UNITY : duplicatePlayer");
                io.Close();
                SceneManager.LoadScene("test");
            });

            // gets called if someone signout of the react client
            io.On("disconnectFromReact", (e) => {
                Debug.Log("UNITY : disconnectFromReact");
                Player player = JsonUtility.FromJson <Player>(e.data);
                Debug.Log(player);
                string id     = player.id;
                GameObject go = serverObjects[id].gameObject;
                Destroy(go);
                serverObjects.Remove(id);
            });

            //gets called if someonecloses a tab
            io.On("disconnected", (e) => {
                Debug.Log("UNITY : disconnect");
                Player player = JsonUtility.FromJson <Player>(e.data);
                Debug.Log(e.data);
                string id = player.id;

                GameObject go = serverObjects[id].gameObject;
                Destroy(go);
                serverObjects.Remove(id);
            });

            io.Connect();
        }
    void Start()
    {
        io = GameObject.Find("SocketIOController").GetComponent <SocketIOController>();
        io.On("connect", (SocketIOEvent e) => {
            Debug.Log("SocketIO connected");



            io.Emit("test-event1");

            TestObject t = new TestObject();
            t.test       = 123;
            t.test2      = "test1";

            io.Emit("test-event2", JsonUtility.ToJson(t));

            TestObject t2 = new TestObject();
            t2.test       = 1234;
            t2.test2      = "test2";

            io.Emit("test-event3", JsonUtility.ToJson(t2), (string data) => {
                Debug.Log(data);
            });
        });

        io.On("allPlayersPositions", (SocketIOEvent ev) => {
            Debug.Log("allPlayersPositions received");
            Debug.Log(ev.data.ToString());
            PlayersList playersList = new PlayersList();
            playersList             = JsonUtility.FromJson <PlayersList>(ev.data);
            foreach (Players player in playersList.Players)
            {
                Debug.Log(player.playerId);
                Debug.Log(player.pos);
                string playerName         = "Player" + player.playerId;
                GameObject playerInstance = Instantiate(playerPrefab, player.pos, Quaternion.identity);
                playerInstance.name       = playerName;
                playerInstance.tag        = "Player";

                /*LocalPlayer localPlayer = playerInstance.GetComponent<LocalPlayer>();
                 * localPlayer.playerId = player.playerId;
                 */
            }
        });

        // delete an instance of the disconnected player
        io.On("playerDisconnected", (SocketIOEvent ev) => {
            string playerId   = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId;
            string playerName = "Player" + playerId;
            Destroy(GameObject.Find(playerName));
        });

        io.On("spawnPlayer", (SocketIOEvent ev) => {
            playerSpawn.GetComponent <SpawnPlayer>().spawnLocalPlayer();
        });

        io.On("moveInput", (SocketIOEvent ev) => {
            Debug.Log("moveInput received : " + ev.data.ToString());
            Movement movement = JsonUtility.FromJson <Movement>(ev.data);
            string playerName = "Player" + movement.playerId;
            GameObject.Find(playerName).GetComponent <PlayerState>().moveInput = movement.moveInput;
        });

        io.On("playerMoved", (SocketIOEvent ev) => {
            Debug.Log("playerMoved received : " + ev.data.ToString());
            PlayerPos playerPos = JsonUtility.FromJson <PlayerPos>(ev.data);
            string playerId     = playerPos.playerId;
            string playerName   = "Player" + playerId;
            Debug.Log(playerName);
            GameObject playerToMove = GameObject.Find(playerName);

            if (playerToMove == null)
            {
                playerToMove      = Instantiate(playerPrefab, playerPos.pos, Quaternion.identity);
                playerToMove.name = playerName;
                playerToMove.tag  = "Player";
                playerToMove.GetComponent <LocalPlayer>().setPlayerId(playerId);
            }

            // TODO: playerToMove.Move(player.pos);

            playerToMove.transform.position = playerPos.pos;
            Debug.Log("playerPos.pos");
            Debug.Log(playerPos.pos);

            /*if(playerToMove != null){
             *  playerToMove.transform.position = playerPos.pos;
             * }
             * else{
             *  Debug.Log("cannot find the playerToMove!");
             * }*/
        });

        io.On("playerRotated", (SocketIOEvent ev) => {
            Debug.Log("playerRotated received : " + ev.data.ToString());
            PlayerPos playerPos = JsonUtility.FromJson <PlayerPos>(ev.data);
            string playerId     = playerPos.playerId;
            string playerName   = "Player" + playerId;
            Debug.Log(playerName);
            GameObject playerToMove = GameObject.Find(playerName);

            playerToMove.transform.eulerAngles = playerPos.pos;
            Debug.Log("playerPos.pos");
            Debug.Log(playerPos.pos);
        });

        io.On("velocityChanged", (SocketIOEvent ev) => {
            Debug.Log("velocityChanged received : " + ev.data.ToString());
            PlayerVelocity playerVelocity = JsonUtility.FromJson <PlayerVelocity>(ev.data);
            string playerId   = playerVelocity.playerId;
            string playerName = "Player" + playerId;
            Debug.Log(playerName);
            GameObject playerToMove = GameObject.Find(playerName);

            playerToMove.GetComponent <PlayerController>().ComputeVelocity(playerVelocity.velocity);

            /*if (playerVelocity.velocity.x == 0)
             * {
             *  playerToMove.GetComponent<Animator>.SetBool("IsRunning", false);
             * }
             * else
             * {
             *  playerToMove.GetComponent<Animator>.SetBool("IsRunning", true);
             * }*/
            Debug.Log("playerVelocity.velocity");
            Debug.Log(playerVelocity.velocity);
        });



        io.On("playerAttack", (SocketIOEvent ev) => {
            Debug.Log("playerAttack received");
            string playerId           = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId;
            string playerName         = "Player" + playerId;
            GameObject playerInstance = GameObject.Find(playerName);
            playerInstance.GetComponent <PlayerState>().isAttacking = true;
            playerInstance.GetComponent <Animator>().SetTrigger("Attack");
        });

        io.On("playerEndAttack", (SocketIOEvent ev) => {
            Debug.Log("playerAttack received");
            string playerId   = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId;
            string playerName = "Player" + playerId;
            GameObject.Find(playerName).GetComponent <PlayerState>().isAttacking = false;
        });

        io.On("jump", (SocketIOEvent ev) => {
            Debug.Log("jump received");
            string playerId   = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId;
            string playerName = "Player" + playerId;
            GameObject.Find(playerName).GetComponent <PlayerState>().jump = true;
        });


        io.On("playerKilled", (SocketIOEvent ev) => {
            Debug.Log("another player killed by a player");
            string playerId   = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId;
            string playerName = "Player" + playerId;
            Destroy(GameObject.Find(playerName));
        });

        io.On("playerDeathByDeathFloor", (SocketIOEvent ev) => {
            Debug.Log("another player killed by death floor");
            string playerId   = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId;
            string playerName = "Player" + playerId;
            Destroy(GameObject.Find(playerName));
        });

        /*io.On("anotherPlayerConnected", (SocketIOEvent e) => {
         *  Debug.Log(e.data);
         *  Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
         * });*/

        io.Connect();

        io.On("test-event", (SocketIOEvent e) => {
            Debug.Log(e.data);
        });
    }