Search Unity

Can't read from sessions?

Discussion in 'Multiplayer' started by Alex1McGrady, Jul 20, 2017.

  1. Alex1McGrady

    Alex1McGrady

    Joined:
    Mar 30, 2016
    Posts:
    48
    Hello guys.I'm trying to take a variable from a php file and print it in my game in unity.The problem is that i don't know how to do it with sessions.When the player logs in i want to take all his stats(health money attack name) and put it into sessions so i can call them wherever i want.When i simple echo something,unity can show it on my screen but if i try to echo a session unity won't do anything.Any ideas?Here is my source codes
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class displayDataFromPhp : MonoBehaviour
    6. {
    7.     public Text dis;
    8.     string answer;
    9.     string url = "http://localhost/CodeIgniterUnity/index.php/Users/";
    10.  
    11.  
    12.     public void Start()
    13.     {
    14.        
    15.         WWW get_www = new WWW(url);
    16.         StartCoroutine(WaitForRequest(get_www));
    17.  
    18.     }
    19.     //Our Coroutine for getting the data
    20.     IEnumerator WaitForRequest(WWW www)
    21.     {
    22.         yield return www;
    23.  
    24.         // check for errors
    25.         if (www.error == null)
    26.         {
    27.  
    28.             //Assign the data that was fetched to the variable answer
    29.             answer = www.text.ToString();
    30.         }
    31.         else {
    32.             Debug.Log("WWW Error: " + www.error);
    33.          
    34.         }
    35.     }
    36.  
    37.     //GUI Components
    38.  
    39.     void OnGUI()
    40.     {
    41.         dis.text = answer;  
    42.         Debug.Log(answer);
    43.  
    44.  
    45.     }
    46. }
    and my php code

    I've already set the sessions in an other file!