I am setting up a leaderboard service that i have implemented with the GooglePlayGames api. My authentication and showing the leaderboard works but my script for posting scores to the leaderboard does not work. I have been looking around for quite a while now and it seems like the syntax for posting score is always the same, which i have aswell.
void Start()
{
AuthenticateUser();
}
void AuthenticateUser()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
Social.localUser.Authenticate((bool success) =>
{
if (success == true)
{
Debug.Log("Logged in to Google play");
}
else
{
Debug.Log("There was an error login in to Google Play");
}
});
}
public static void PostToLeaderboard(long newScore)
{
Social.ReportScore(10, GPGSIds.leaderboard_highscore, (bool success) =>
{
if (success == true)
{
Debug.Log("Score were sucessfully added to leaderboard");
}
else
{
Debug.Log("Unable to post score to leaderboard");
}
});
}
This is my code for authenticating and post score to the leaderboard. I have hard coded 10 in the code Social.ReportScore function call.
Any ideas on why this is? The leaderboardUI shows up but no scores.
Please make sure to run the method PostToLeaderboard(long newScore) to update your leaderboard before you call leaderboardUI method.
Here in this case you can try this.
puplic void leaderboardUI() {
PostToLeaderboard(long newScore);
// your code to show leaderboard
}
Related
When the Continue Ads gameobject is closed, the Game over button works, but when the Continue Ads is turned on, the Game over button does not work. I cannot understand why I make a mistake?
!Me fixed the problem, the problem is that I noticed that it is related to the continue ads dimension, thank you for your time.
void Update()
{
if (Application.internetReachability == NetworkReachability.NotReachable)
{
//Debug.Log("No internet access");
Destroy(GameObject.FindWithTag("ContinuePanel"));
}
else
{
//Debug.Log("internet connection");
if (tag == "Skull")
{
ContinueAds();
}
}
}
public void ContinueAds()
{
gameObject.AddComponent<AdsScript1>();
gameoverPanel.SetActive(false);
PausedGamePanel();
}
public void GameoverButton()
{
gameoverPanel.SetActive(false);
SceneManager.LoadScene(0);
}
Your continue ads object is in gameover panel. When you set gameoverPanel.SetActive(false) you also do the same on the child objects.
I am trying to setup a Facebook marketing campaign with the objective being to track app installs. Facebook recommends using their SDK to get accurate information about app installs, but I don't want to prompt the user to login to Facebook in my app. Is it possible to have the Facebook SDK track app installs without users logging in? According to Facebook their API automatically tracks app installs but it seems that in their initialization script called mainmenu.cs requires a Facebook login to occur.
What I did was basically create a persistent game object in my first scene and attached this code to it. I based this code off of Facebook's example https://developers.facebook.com/docs/app-events/unity but added some additional checks so FB.Init() would not be called twice. I also added a coroutine that would wait to activate an event until FB.Init() is done since FB.Init() is an asynchronous function.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Facebook.Unity;
public class FacebookTracker : MonoBehaviour {
private static FacebookTracker instance;
private bool initCalled;
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
} else
{
Destroy(gameObject);
}
if (FB.IsInitialized == false && initCalled == false)
{
FB.Init();
initCalled = true;
}
}
private void OnApplicationPause(bool pause)
{
Debug.Log("OnApplicationPause = " + pause);
if (pause == false)
{
if (FB.IsInitialized == true)
{
FB.ActivateApp();
} else
{
if (initCalled == false)
{
FB.Init();
initCalled = true;
}
StartCoroutine(ActivateEvent());
}
}
}
private IEnumerator ActivateEvent()
{
yield return new WaitUntil(() => FB.IsInitialized == true);
Debug.Log("Facebook Activate Event Logged");
FB.ActivateApp();
}
}
I am trying to get Google play services into the game I have developed. Here is the script I have on my main screen. I get no response out of it at all. I have tried all the different SHA1 codes and I am not sure what is wrong. Any Ideas???
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.UI;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
public class GPS_Main : MonoBehaviour {
private bool IsConnectedToGoogleServices;
public Text SignIn;
private void Awake()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
}
// Use this for initialization
void Start () {
LogIn();
}
// Update is called once per frame
void Update () {
}
void LogIn()
{
Social.localUser.Authenticate(success => { });
}
public bool ConnectToGoogleServices()
{
if (!IsConnectedToGoogleServices)
{
Social.localUser.Authenticate((bool success) =>
{
IsConnectedToGoogleServices = success;
});
}
return IsConnectedToGoogleServices;
}
public static void ToAchievementUI()
{
if (Social.localUser.authenticated)
{
Social.ShowAchievementsUI();
}
else
{
Debug.Log("Not authenticated");
}
}
}
This has really been an annoying event. I have been through many videos and books trying to find the correct fix.
There are many things that cause this to happen, the best way to find it is to try connecting your phone and then using adb logcat to see what is causing the problem.
Also i have found a little bug in your function ConnectToGoogleServices :
public bool ConnectToGoogleServices()
{
if (!IsConnectedToGoogleServices)
{
Social.localUser.Authenticate((bool success) =>
{
IsConnectedToGoogleServices = success;
});
}
return IsConnectedToGoogleServices;
}
This function is always returning IsConnectedToGoogleServices initial state.
I tried a bit of explanation in this post Google Play Sign in for Unity
, however I can't understand from your question what are all options you have tried and where you are stuck in your problem. 6 months old question at the time of me writing this. Hope you've sorted this out already. If so, please post your findings here that may help others.
For anyone landing on this question for an answer, pls refer to my answer on the other post (link above) if that is of any help for your problem and also note down the problem in the code (on the question), I think AminSojoudi tried pointing it out as well. Social.localUser.Authenticate() is taking the argument of a callback function (refer documentation). So don't expect it to assign IsConnectedToGoogleServices the result (success or failure) within ConnectToGoogleServices() scope itself. If Authenticate() call runs faster than your code execution, you may get a success, but that won't happen and your function won't return the actual success status of Authenticate() function call anytime. If your rest of the code (leaderboard, achievements) relies on IsConnectedToGoogleServices Boolean flag, then those will not work as well.
public bool ConnectToGoogleServices()
{
if (!IsConnectedToGoogleServices)
{
Social.localUser.Authenticate((bool success) =>
{
IsConnectedToGoogleServices = success; // <-- callback result
});
}
return IsConnectedToGoogleServices; // <-- this won't return the result of a callback result.
}
I want in my unity game with firebase facebook login when user login through facebook there user name, email & profile picture save in firebase.
I tried from firebase unity login auth docs but i cant get any thing from there.
On there docs to difficult to understand for beginners.
using UnityEngine;
using Facebook.Unity;
using UnityEngine.UI;
using Firebase.Auth;
public class FacebookManager : MonoBehaviour
{
public Text userIdText;
private FirebaseAuth mAuth;
private void Awake()
{
if (!FB.IsInitialized)
{
FB.Init();
}
else
{
FB.ActivateApp();
}
}
public void LogIn()
{
FB.LogInWithReadPermissions(callback:OnLogIn);
}
private void OnLogIn(ILoginResult result)
{
if (FB.IsLoggedIn)
{
AccessToken tocken = AccessToken.CurrentAccessToken;
userIdText.text = tocken.UserId;
Credential credential =FacebookAuthProvider.GetCredential(tocken.UserId);
}
else
{
Debug.Log("Login Failed");
}
}
public void accessToken(Credential firebaseResult)
{
FirebaseAuth auth = FirebaseAuth.DefaultInstance;
if (!FB.IsLoggedIn)
{
return;
}
auth.SignInWithCredentialAsync(firebaseResult).ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("SignInWithCredentialAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
return;
}
FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
}
}
Please help me i am beginner in coding
Image
tocken.UserId This is wrong. Use tocken.TokenString . This will solve your problem. :)
I just start write my first game with unity.
I Created on facebook app - in games category.
I downloaded Facebook idk and added to unity.
I changed app id in Facebook settings.
Now I tried my code:
public class LoginScript : MonoBehaviour {
public string resultstr { get; set; }
public Text LableResult { get; set; }
List<string> perms = new List<string> (){"public_profile", "email", "user_friends"};
// Use this for initialization
void Start () {
LableResult = gameObject.GetComponent<Text> ();
LableResult.text = "Test";
if (!FB.IsInitialized) {
// Initialize the Facebook SDK
FB.Init (InitCallback, OnHideUnity);
} else {
// Already initialized, signal an app activation App Event
FB.ActivateApp ();
}
}
private void InitCallback ()
{
if (FB.IsInitialized) {
// Signal an app activation App Event
FB.ActivateApp ();
// Continue with Facebook SDK
// ...
} else {
Debug.Log ("Failed to Initialize the Facebook SDK");
}
}
private void OnHideUnity (bool isGameShown)
{
if (!isGameShown) {
// Pause the game - we will need to hide
Time.timeScale = 0;
} else {
// Resume the game - we're getting focus again
Time.timeScale = 1;
}
}
// Update is called once per frame
void Update () {
}
private void AuthCallback (ILoginResult result)
{
if (FB.IsLoggedIn) {
// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log (aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions) {
Debug.Log (perm);
}
} else {
Debug.Log ("User cancelled login");
}
}
// On Facebook login button
public void OnFacebook ()
{
FB.LogInWithReadPermissions (perms, AuthCallback);
}
}
But I'm ALWAYS getting in Result:
Graph Api Error: 400 Bad request
And callback_id 2 (sometimes I've seen 3)
Login I try in Mock window with token from facebook.
I tried deploy on iPhone - and game just crashed when I click on login button
Please to close this topic. I fixed it. It was my fail )) (Used app token instead user token )) (Happends)))))
The same thing happened to me!
Remember to check the user token part, which won't be set by default!