i want show username in gui label from mysql database in another scene after login succes…
but nothing diplayed
sry for english
using UnityEngine;
using System.Collections;
public class name : MonoBehaviour {
string username;
string password;
void OnGUI(){
GUI.Label(new Rect(826,251,70,40) , username);
}
void Start(){
StartCoroutine (registerFunc (username,password));
}
IEnumerator registerFunc (string username, string password)
{
string url = "http://localhost/tester/login.php";
WWW www = new WWW(url);
yield return www;
username = www.text;
}
}
The function GUI.Label() returns a string value that should be the new value of your username field.
Right now, you’re not actually changing the value of username. In other words, it’s never being assigned to.
username = GUI.Label(new Rect(826,251,70,40) , username);
Avoid using the same variable names locally in functions as the global ones. Inside IEnumerator, change username
and password
to something like user
and pass
. Not much can be done with this much of information.
Also, you are not setting username to anything at all. Change GUI.Label(new Rect(826,251,70,40) , username);
to username = GUI.Label(new Rect(826,251,70,40) , username);
tnx … i have error Assets/name.cs(13,17): error CS0029: Cannot implicitly convert type void' to
string’