Documentation
Ask or search…
K
Links
Comment on page

Unity services sign in

To start a game, each player needs to sign in with a user name. Note: Name is required but should not contain blank spaces or special characters.

Overview

In the Lobby scene, players enter their names to either create a room or search for one.
Create a game object and attach the "Local With Lobby" script.

Login

  1. 1.
    Enter your profile name.
  2. 2.
    Sign in to join the game and move to the Room object.
Sign in screen
// Unity-Survival-Engine-Online/Assets/SurvivalEngine/Scripts/Tashi/LocalWithLobby.cs
public async void SignInButtonClicked()
    {
        if (string.IsNullOrEmpty(profileName.text))
        {
            Debug.Log($"Signing in with the default profile");
            profileNameText.text = $"Name: Player";
            await UnityServices.InitializeAsync();
        }
        else
        {
            Debug.Log($"Signing in with profile '{profileName.text}'");
            var options = new InitializationOptions();
            options.SetProfile(profileName.text);
            profileNameText.text = $"Name: {profileName.text}";
            LobbyManager.Get.ProfileName = profileName.text;
            await UnityServices.InitializeAsync(options);
        }
        try
        {
            AuthenticationService.Instance.SignedIn += delegate
            {
                profileMenu.SetActive(false);
                lobbyMenu.SetActive(true);
                FilteringLobbies();
            };
            await AuthenticationService.Instance.SignInAnonymouslyAsync();
        }
        catch (Exception e)
        {
            Debug.LogException(e);
            throw;
        }
    }