Okay maybe I’m just missing something blatantly obvious here and sorry if that’s the case, but I’m stumped. I’m trying to adjust my Google Play Services log-in and cloud save system to have a little more flexibility. This is my code (I’ll only provide the relevant sections):
void Start () {
ActivateSocialPlatform ();
LoginSuccess = false;
Login ();
}
private void Login(){
DebugText.text += "Starting login process
";
GooglePlaySignIn ();
if (LoginSuccess == true) {
LoadData();
} else {
DebugText.text += "Something went wrong
";
}
}
public void GooglePlaySignIn(){
DebugText.text += "Signing into Google Play
";
Social.localUser.Authenticate ((bool success) => {
if (success) {
DebugText.text += "Google Play authentification success
";
LoginSuccess = true;
} else {
DebugText.text += "Google Play authentification failed
";
LoginSuccess = false;
}
});
}
Basically, I call Login() to start the authentification process in GooglePlaySignIn(), which is supposed to set the variable LoginSuccess either true or false, and if it’s true, I start loading savedata from the cloud. However I end up with a log like this:
Activating Social Platform
Starting login process
Signing into Google Play
Something went wrong
Google Play authentification success
As I understand, for some reason the function Login() doesn’t wait until GooglePlaySignIn() completes and continues into the false state, AFTER which the user is actually signed on. Why does this happen? I thought all functions are supposed to wait until their called functions complete before continuing with their own code? Everything works just fine if I place the authentification code inside Login() itself, instead of having it in a separate function. I want to be able to reuse this code though, instead of having to duplicate it every time I need the user to log in again.
Thanks in advance.