Preventing that method from continuing until the Firebase database has returned a value would be a bad idea, because it would freeze the whole game process. So a function bool IsNameAvailable (string nick) is simply not going to work when it needs to access a remote resource. You will have to work with asynchronously called callback-methods in this case. There is really no good way around it.
That means you don't have a IsNameAvailable method which returns bool, you have one which returns void and receives a method as an additional parameter which gets called as soon as it got a result from the database.
So instead of this code:
if (IsNameAvailable (nick) ) { textlabel.text = "Name is available"; } else { textlabel.text = "Name is already taken"; }
You will have to pass a callback-method to IsNameAvailable which gets executed as soon as the database is finished:
IsNameAvailable (nick, NameCheckCallback); /*...*/ private void NameCheckCallback(bool success) { if (success) { textlabel.text = "Name is available"; } else { textlabel.text = "Name is already taken"; } }
Your IsNameAvailable function would then look like this:
private void IsNameAvailable (string nick, Action<bool> callbackFunction) { FirebaseDatabase.DefaultInstance.GetReference ("users").OrderByChild ("name").EqualTo (nick).GetValueAsync ().ContinueWith (task => { if (task.IsFaulted) { Debug.LogError ("A error encountered: " + task.Exception); } else if (task.IsCanceled) { Debug.LogError ("Canceled ..."); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; callbackFunction(snapshot.GetValue(true) == null); } }); }