Hello guys.I want to display some data from a php file to my unity.The problem is unity doesn’t display it but if i put Debug.log i can see them.
My php code
As you can see if i login with my localhost(like if i was on a website) i can see all my table rows,the session username and the number 100(which i put it as a test).
Now the unity part:
This is my code when i want to login
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class internetCalls : MonoBehaviour
{
public static internetCalls _Instance;
public bool IsLoggedIn = false;
public string LoggedInUsername = "";
public string message = "";
public displayDataFromPhp display;
public bool IsSamurai = false;
void Start()
{
_Instance = this;
DontDestroyOnLoad(this.gameObject);
}
public void OnGUI()
{
if (message != "")
GUILayout.Box(message);
}
public void DoLogin(string user, string password)
{
WWWForm www = new WWWForm();
www.AddField("user", user);
www.AddField("password", password);
WWW w = new WWW("http://localhost/CodeIgniterUnity/index.php/Users/login", www);
StartCoroutine(Login(w, user));
LoggedInUsername = user;
Debug.Log("Logged in: " + user);
}
public void DoRegisterSamurai(string user, string name, string password)
{
WWWForm www = new WWWForm();
www.AddField("user", user);
www.AddField("name", name);
www.AddField("password", password);
WWW w = new WWW("http://localhost/CodeIgniterUnity/index.php/Users/registerSam", www);
StartCoroutine(Register(w));
}
public void DoRegisterKnight(string user, string name, string password)
{
WWWForm www = new WWWForm();
www.AddField("user", user);
www.AddField("name", name);
www.AddField("password", password);
WWW w = new WWW("http://localhost/CodeIgniterUnity/index.php/Users/registerKnight", www);
StartCoroutine(Register(w));
}
public IEnumerator Register(WWW w)
{
yield return w;
if (w.error == null)
{
message += "Register Good!!!";
}
else
{
message += "Couldn't Connect";
}
}
public IEnumerator Login(WWW w, string user)
{
yield return w;
if (w.error != null)
{
message += "Login Good!!!";
IsLoggedIn = true;
LoggedInUsername = user;
Debug.Log("Logged in: " + user);
UnityEngine.SceneManagement.SceneManager.LoadScene("map");
}
else
{
message += "Couldn't Connect";
}
}
}
and this is my code (in the next scene after the user logs in) to display the data when he logs in.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class displayDataFromPhp : MonoBehaviour
{
public Text dis;
string answer;
string url = "http://localhost/CodeIgniterUnity/index.php/Users/";
public void Start()
{
WWW get_www = new WWW(url);
StartCoroutine(WaitForRequest(get_www));
}
IEnumerator WaitForRequest(WWW www)
{
yield return www;
if (www.error == null)
{
answer = www.text.ToString();
}
else {
Debug.Log("WWW Error: " + www.error);
}
}
void OnGUI()
{
dis.text = answer; //emfanizei apo tin vasi mou ta stoixeia
Debug.Log(answer);
}
}
As you can see when i log in with unity it shows ONLY the number 100(which i put to test it in my php file at the beggining)
In the debug log i can see the number 100 AND my database table but NOT the session username.
What i want is to somehow show instead of the green 100,the username session(which is not even in the debug log).Any ideas?
P.S sorry for my english!



