Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator getPlayers(bool running)
- {
- Debug.Log("DAHAL-------METH-----------------");
- string querystring = "?operation=select";
- string fullURL = url+querystring;
- while (true) {
- Debug.Log("DAHAL------WHILE------------------");
- //http://localhost:8084/example1/index.php?operation=SELECT
- Debug.Log(fullURL);
- WWW webresult = new WWW(fullURL);
- //wait for the result of the web query
- yield return webresult;
- string[] records = webresult.text.Split('%');
- foreach (string record in records){
- try{
- Debug.Log("DAHAL-------FOR-----------------");
- //Debug.Log(record);
- string[] fields = record.Split('|');
- if (int.Parse(fields[0]) != currentPlayer.GetComponent<playerController>().playerID)
- {
- Debug.Log("DAHAL------IF------------------");
- canAdd = true;
- foreach (GameObject p in currentPlayers)
- {
- if (p.GetComponent<nonplayerController>().playerID == int.Parse(fields[0]))
- {
- canAdd = false;
- }
- }
- //add the player to the list
- //check the ids, filter the IDs of the players who are already in the game
- if (canAdd)
- {
- //instantiate a box at each position
- GameObject playerBox = Instantiate(player,
- new Vector3(float.Parse(fields[5]),float.Parse(fields[6])),
- Quaternion.identity);
- playerBox.name = fields[1];
- //restore the colour & shape from the server
- //-----------------------------------
- //-----------------Shape------------
- if (fields[4] == "Circle"){
- playerBox.GetComponent<SpriteRenderer>().sprite = circleSprite;
- Debug.Log("circ-----------------------------");
- }else if (fields[4] == "Square")
- {
- playerBox.GetComponent<SpriteRenderer>().sprite = squareSprite;
- Debug.Log("SQUAAARE-----------------------------");
- }else if (fields[4] == "Diamond"){
- playerBox.GetComponent<SpriteRenderer>().sprite = diamondSprite;
- Debug.Log("Diamoonds-----------------------------");
- }else{
- Debug.Log("----------------how? not getting info");
- }
- //----------------------------------------
- //-------------Colour--------------------
- if (fields[3] == "Red"){
- playerBox.GetComponent<SpriteRenderer>().color = Color.red;
- Debug.Log("RED------------------------------------");
- }else if (fields[3] == "Green"){
- playerBox.GetComponent<SpriteRenderer>().color = Color.green;
- Debug.Log("Green------------------------------");
- }else if (fields[3] == "Blue"){
- playerBox.GetComponent<SpriteRenderer>().color = Color.blue;
- }else{
- Debug.Log("----------------how? not getting info");
- }
- //set the name of each player box
- playerBox.GetComponentInChildren<TextMesh>().text = playerBox.name;
- playerBox.AddComponent<nonplayerController>();
- //get the ID from the database and add it to the script inside playerbox
- playerBox.GetComponent<nonplayerController>().playerID = int.Parse(fields[0]);
- int playeridtoadd = int.Parse(fields[0]);
- currentPlayers.Add(playerBox);
- }
- }
- }catch(System.Exception e){
- Debug.Log(e);
- }
- }
- //run the join game script AFTER I have loaded all the players on the web server
- if (!running){
- joinGameOnServer();
- break;
- } else {
- //sync users every 2 seconds
- Debug.Log("Synced users again"+Time.time);
- yield return new WaitForSeconds(2f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement