Ejemplo n.º 1
0
    public void UpdateScore(Player data)
    {
        Debug.Log(" before send score");

        string playerAsJson = PlayerJSON.CreateToJSON(data);

        io.Emit("updateScore", playerAsJson);
    }
Ejemplo n.º 2
0
    IEnumerator JoinTheGame(object data)
    {
        Debug.Log("JoinGame");
        Debug.Log(data);


        yield return(new WaitForSeconds(0.3f));

        io.Emit("player connect");
        StartCoroutine(getTopScore());

        yield return(new WaitForSeconds(0.5f));

        UserJSON user = JsonUtility.FromJson <UserJSON>(data.ToString());


        canvas.gameObject.SetActive(false);
        c1.gameObject.SetActive(false);
        Vector3    position   = new Vector3(0, 5, 0);
        Quaternion rotation   = Quaternion.Euler(0, 0, 0);
        GameObject playerCstr = Instantiate(playerPrefab, position, rotation) as GameObject;



        Player pC = playerCstr.GetComponent <Player>();

        pC.isLocalPlayer   = true;
        pC.pseudo          = user.pseudo;
        pC.Hscore          = user.score;
        pC.Hscorehud.text  = "Highscore :" + user.score;
        pC.currentPosition = position;
        pC.currentRotation = rotation;

        string playerAsJson = PlayerJSON.CreateToJSON(pC);


        io.Emit("play", playerAsJson);

        Transform t          = playerCstr.transform.Find("Canvas");
        Transform t1         = t.transform.Find("pseudo");
        Text      playerName = t1.GetComponent <Text>();

        playerName.text = pC.pseudo;
        playerCstr.name = pC.pseudo;
        localName       = pC.pseudo;
        Debug.Log(playerName.text);
        Debug.Log(user.score);
        myPlayer = playerCstr;
    }
Ejemplo n.º 3
0
    //fierce-stream-59902.herokuapp.com

    public void UpdateHighScore(Player data)
    {
        Debug.Log(" before send highscore");
        Debug.Log(data);

        string playerAsJson = PlayerJSON.CreateToJSON(data);

        //io.Emit("updateHighScore", playerAsJson);

        byte[]          myfData = System.Text.Encoding.UTF8.GetBytes(playerAsJson);
        UnityWebRequest www     = UnityWebRequest.Put("https://fierce-stream-59902.herokuapp.com/user/score/", myfData);

        www.SetRequestHeader("Content-Type", "application/json");

        StartCoroutine(OnScoreResponse(www));
    }
Ejemplo n.º 4
0
    private IEnumerator OnScoreResponse(UnityWebRequest req)
    {
        yield return(req.Send());

        Debug.Log(" after send highscore");
        Debug.Log(req);
        if (req.isNetworkError || req.isHttpError)
        {
            Debug.Log(req.error);
        }
        else
        {
            Debug.Log("Upload complete!");
            Debug.Log(req.downloadHandler.text);
            string playerAsJson = PlayerJSON.CreateToJSON(myPlayer.GetComponent <Player>());
            io.Emit("updateHighScore", playerAsJson);
        }
    }