Google Play Services Singleton HELP!
Firstly Hello, I am new to Unity and coding.. I made simple Trivia game which has 5 scenes in it. Now I want to publish it to Google Play Store but before I need to add Google Play Services to game. I tried many things but I failed. I think I must make with singleton but I don't know how to do it. Maybe someone can help me or show the way... I installed GitHub Plugin and made setup for android. Also followed the GitHub's instructions but did not worked... Any suggestions or help ?
Thanks anyway!
Answer by paradox9 · May 25, 2017 at 02:57 PM
@Vaell Hi,
this might help :-
Create a new Empty object in your starting scenes (maybe your menu scene)
Create a new C# Script : PlayGameManager.cs
using UnityEngine; using GooglePlayGames; using GooglePlayGames.BasicApi; using UnityEngine.SocialPlatforms; public class PlayGameManger : MonoBehaviour { public static PlayGameManger Instance{ set; get;} public bool isLogedIn; void Awake () { if (Instance == null) { Instance = this; isLogedIn = false; PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder ().Build(); PlayGamesPlatform.InitializeInstance (config); PlayGamesPlatform.DebugLogEnabled = true; PlayGamesPlatform.Activate (); SignIn (); DontDestroyOnLoad (gameObject); } else { Destroy (gameObject); } } public void SignIn(){ if (isLogedIn == false) { Social.localUser.Authenticate (success => { isLogedIn = success; //Debug.Log("Signin : "+success); }); } } // your Achievements and other code here }
Add this script to that new Empty object.
to access properties from this script in other scripts, eg.:
//in other script if (PlayGameManger.Instance != null) { PlayGameManger.Instance.ShowLeaderboardsUI (); }
Done! this script will available in all scenes
Answer by Akki-bhatt · Aug 19, 2017 at 05:23 AM
You can get full play service integration here : http://u3d.as/UHs