// Update is called once per frame
    void Update()
    {
        counter += 1;
        if (counter > 5)
        {
            // add 3 after Hello, World! to tell server which shadow to load
            s_tcp.writeSocket("Hello, World!3");
            byte[] buffer = s_tcp.readSocket();
            if (buffer != null && buffer.Length > 0)
            {
                Debug.Log("Received:" + Encoding.ASCII.GetString(buffer, 0, 5));
                // Create a texture. Texture size does not matter, since
                // LoadImage will replace with with incoming image size.
                if (buffer.Length < 10)
                {
                    Debug.Log("Succeed");
                    current_score = 100;
                    succeed       = true;
                    congrats.SetActive(true);
                    success_counter = counter_text;
                    // SceneManager.LoadScene (5);
                }
                else
                {
                    Texture2D tex       = new Texture2D(2, 2);
                    byte[]    score_buf = new byte[2];
                    byte[]    img_buf   = new byte[buffer.Length - 2];
                    Buffer.BlockCopy(buffer, 0, score_buf, 0, 2);
                    Buffer.BlockCopy(buffer, 2, img_buf, 0, img_buf.Length);
                    tex.LoadImage(img_buf);
                    GetComponent <Renderer> ().material.SetTexture("_MainTex", tex);
                    score           = System.Text.Encoding.UTF8.GetString(score_buf);
                    scoreboard.text = "Score " + score;
                    current_score   = Int32.Parse(score);
                    // scoreboard.text = "Score " + System.Text.Encoding.UTF8.GetString(score_buf);
                    // tex.LoadImage (buffer);
                    // GetComponent<Renderer> ().material.SetTexture ("_MainTex", tex);
                }
            }
            else
            {
                //Debug.Log ("Received nothing.");
            }
            counter = 0;
        }

        counter_text += 1;

        // hit space to move to the next scene
        // or wait for around a second to jump to the next level
        // if user succeeds
        if (counter_text > success_counter + 50 && succeed || Input.GetKeyDown("space"))
        {
            SceneManager.LoadScene(4);
        }
    }
Exemplo n.º 2
0
        protected virtual void handleCreateSession()
        {
            String response;

            if (actualState == 1)
            {
                mainThread.writeSocket("NEWSESSION");
                actualState = 2;
            }

            if (actualState == 2)
            {
                sessionID = mainThread.readSocket();
                if (sessionID != "")
                {
                    actualState = 3;
                }
            }

            if (actualState == 3)
            {
                response = mainThread.readSocket();
                if (response != "")
                {
                    actualState = 0;
                }
            }

            if (actualState == 0)
            {
                operation = 0;
            }
        }
    // Update is called once per frame
    void Update()
    {
        counter += 1;
        if (counter > 5)
        {
            // add 0 after Hello, World! to tell server which shadow to load
            s_tcp.writeSocket("Hello, World!0");
            byte[] buffer = s_tcp.readSocket();
            if (buffer != null && buffer.Length > 0)
            {
                Debug.Log("Received:" + Encoding.ASCII.GetString(buffer, 0, 5));
                // Create a texture. Texture size does not matter, since
                // LoadImage will replace with with incoming image size.
                if (buffer.Length < 10)
                {
                    Debug.Log("Succeed");
                    current_score = 100;
                }
                else
                {
                    Texture2D tex       = new Texture2D(2, 2);
                    byte[]    score_buf = new byte[2];
                    byte[]    img_buf   = new byte[buffer.Length - 2];
                    Buffer.BlockCopy(buffer, 0, score_buf, 0, 2);
                    Buffer.BlockCopy(buffer, 2, img_buf, 0, img_buf.Length);
                    tex.LoadImage(img_buf);
                    GetComponent <Renderer> ().material.SetTexture("_MainTex", tex);
                    score           = System.Text.Encoding.UTF8.GetString(score_buf);
                    scoreboard.text = "Score " + score;
                    current_score   = Int32.Parse(score);
                    // tex.LoadImage (buffer);
                    // GetComponent<Renderer> ().material.SetTexture ("_MainTex", tex);
                }
            }
            else
            {
                //Debug.Log ("Received nothing.");
            }
            counter = 0;
        }

        counter_text += 1;
        if (counter_text == 100)
        {
            tutorial.text = tutorial_1;
        }
        else if (counter_text > 100 && counter_text % 50 == 0)
        {
            // use counter_text and current_score to
            // decide which instruction to show
            if (succeed == true)
            {
                SceneManager.LoadScene(2);
            }
            if (current_score < 20)
            {
                tutorial.text = tutorial_1;
            }
            else if (current_score >= 20 && current_score <= 80)
            {
                tutorial.text = tutorial_2;
            }
            else if (current_score > 80 && current_score < 100)
            {
                tutorial.text = tutorial_3;
            }
            else
            {
                tutorial.text = tutorial_4;
                congrats.SetActive(true);
                succeed = true;
            }
        }

        // hit space to move to the next scene
        if (Input.GetKeyDown("space"))
        {
            SceneManager.LoadScene(2);
        }
    }
Exemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     myTCP = gameObject.AddComponent<s_TCP> ();
         //new s_TCP();
     myTCP.setupSocket();
     Debug.Log (myTCP.socketReady);
     myTCP.writeSocket("get me started");//request data
 }