but what i would like, to add at the .Name and .Score is the values i retrieve from a database like. I retrieve them already in my MainLogin.cs:
IEnumerator getCharacters()
{
WWWForm Form = new WWWForm();
Form.AddField("Email", email);
Form.AddField("Password", password);
WWW GetItemsWWW = new WWW(charactersURL, Form);
yield return GetItemsWWW;
if (GetItemsWWW.error != null)
{
Debug.LogError("Cant connect to character selection!");
}
else
{
string LogText = GetItemsWWW.text;
//Debug.Log(LogText);
string[] LogTextSplit = LogText.Split(',');
for (int i = 0; i < LogTextSplit.Length; i++)
{
Debug.Log(LogTextSplit[i]);
CH.showCanv(LogTextSplit);
}
CharSelCanv.SetActive(true);
}
}
Inside of LogTextSplit is the character name.
How can i manage to retrieve the LogTextSplit inside of my Balance.cs? The first code i showed you, i cant figure this out
Well, first, I think you need to figure out the timing of all this. Your login code appears to be a coroutine, and fetches data from the web, so getting that LogTextSplit data is going to happen well after the start of the scene. Yet your Balance.cs is instantiating something as soon as the level is loaded.
So, unless Balance.cs runs in some later scene than where MainLogin.cs runs, there is no way that data is going to be available by the time it’s instantiating stuff.
So maybe instead of instantiating things as soon as the level is loaded, you want to wait and do it after login? In that case, here’s how I would do it:
Make a public method in Balance.cs that does this instantiation.
Make a public UnityEvent in MainLogin, and invoke that at the end of the login coroutine.
Hook the event up to the Balance instantiation method in the inspector.
If you’re not familiar with Unity events, here’s a quick tutorial I did on them a while back.
In that case, all you really need to do is store your login data someplace easily accessible. For example, some public static fields, declared like so:
public class MainLogin : MonoBehaviour {
public string LogText;
public string[] LogTextSplit;
....
And then store to these rather than to local variables in your coroutine. Then in your other script, you can reference those fields directly, as MainLogin.LogText or MainLogin.LogTextSplit.
Well I don’t know what your intent is. You seem to have an array of strings in one place, and want just a single string in the other place. Which string do you want? Only you can say.