0

I've been trying to integrate facebook into my project and I've successfully managed to do just that with the help of some online tutorials however I do have one persisting problem...

The code is set to pause the game using

Time.timescale = 0; when a facebook window is up and to resume play using Time.timescale = 1; when it's not

but that just doesn't happen, and the function that pauses the game never gets called...

Here's the code :

using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 
 public class FBHolder : MonoBehaviour {
 
     public GameObject UIFBIsLoggedIn;
     public GameObject UIFBNotLoggedIn;
     public GameObject UIFBAvatar;
     public GameObject UIFBUserName;
     
 
     public GameObject ScoreEntryPanel;
     public GameObject ScoreScrollList;
 
     private List<object> scoreslist = null;
 
     private Dictionary<string, string> profile = null;
 
     void Awake()
     {
         FB.Init (SetInit, onHideUnity);
     }
 
     private void SetInit()
     {
         Debug.Log ("FB Init Done");
 
         if(FB.IsLoggedIn)
             {
                 Debug.Log ("FB Logged In");
                 managefbmenus(true);
             }
         else
             {
                 managefbmenus(false);
             }
 
     }
 
     private void onHideUnity(bool isGameShown)
     {
         if(!isGameShown)
             {
                 Debug.Log ("Pause Game");
                 Time.timeScale = 0;
             }
         else
             {
                 Time.timeScale = 1;
             }
     }
 
     public void FBLogin()
     {
         FB.Login ("email,publish_actions", Authcallback);
     }
 
     void Authcallback(FBResult result)
     {
         if(FB.IsLoggedIn)
             {
                 Debug.Log ("FB Login Worked");
                 managefbmenus(true);
             }
         else
             {
                 Debug.Log ("FB Login Failed");
                 managefbmenus(false);
             }
     }
 
     void managefbmenus(bool isLoggedIn)
     {
         if(isLoggedIn)
             {
                 UIFBIsLoggedIn.SetActive(true);
                 UIFBNotLoggedIn.SetActive(false);
                 SetScore();
 
                 //Get profile picture
                 FB.API(Util.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, DealWithProfilePicture);
                 FB.API("/me?fields=id,first_name", Facebook.HttpMethod.GET,DealwithUserName);
                 //Get username
             }
         if(!isLoggedIn)
             {
                 UIFBIsLoggedIn.SetActive(false);
                 UIFBNotLoggedIn.SetActive(true);
             }
     }
 
 
     void DealWithProfilePicture(FBResult result)
     {
         if(result.Error != null)
         {
             Debug.Log ("Problem getting profile picture");
             FB.API(Util.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, DealWithProfilePicture);
             return;
         }
         Image UserAvatar = UIFBAvatar.GetComponent<Image> ();
         UserAvatar.sprite = Sprite.Create (result.Texture, new Rect(0, 0, 128, 128), new Vector2(0, 0));
     }
 
     void DealwithUserName(FBResult result)
     {
         if(result.Error != null)
         {
             Debug.Log ("Problem getting username");
             FB.API("/me?fields=id,first_name", Facebook.HttpMethod.GET,DealwithUserName);
             return;
         }
         profile = Util.DeserializeJSONProfile(result.Text);
 
         Text UserMsg = UIFBUserName.GetComponent<Text>();
 
         UserMsg.text = "Hello, " + profile ["first_name"];
     }

Any ideas on what could be causing this issue?

BTW: I'm using unity 5.

Randy Levy
  • 22,566
  • 4
  • 68
  • 94

1 Answers1

0

I guess you don't need to pause your game while Facebook UI is displayed. you can just call it as:

 FB.Init(SetInit); 
Umair M
  • 10,298
  • 6
  • 42
  • 74
  • That wouldn't work for me because the facebook windows usually turn up on top of some clickable ui elements so whenever I try to do a facebook action I end up messing with something underneath it. – Mohammed Gameal Aug 07 '15 at 09:36
  • you can use a separate empty ui panel to avoid interactions with your underneath UI. You can see [FriendSmash Sample Code](https://github.com/fbsamples/friendsmash-unity) to figure out where you are wrong. – Umair M Aug 07 '15 at 10:01
  • First off I'd like to thank you for trying to help however I'd like to point out that I'm a novice programmer and usually get help from online tutorials which is how I got this whole facebook integration this working in the first place, and everything is indeed working as expected except for that little bit.. I tried looking at the friendsmash sample code you pointed out but I just couldn't follow what goes where and I think the workflow they're using is much different than mine, all I'm missing is getting the onHideUnity function to get called when a facebook popup dialogue is displayed ... – Mohammed Gameal Aug 10 '15 at 21:05