//Ensures there is only one instance of this script private void Awake() { if (instance != null) { Debug.Log("More than one build manager exists"); return; } instance = this; }
//Initializes the scene and and checks if player is eligble for daily bonus //Checks if the player already has a village as well void Start() { FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://finalprojectunity-31171.firebaseio.com//"); PlayerCheck = WorldScenePlayerCollisionDetection.instance; makeVillage.gameObject.SetActive(false); helpPanel.SetActive(false); InitializeFirebase(); alreadyHasVil = false; Debug.Log("This "); auth = Firebase.Auth.FirebaseAuth.DefaultInstance; user = auth.CurrentUser; email = user.Email; //Debug.Log(email); userNameText.text = email; //FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://finalprojectunity-31171.firebaseio.com//"); reference = FirebaseDatabase.DefaultInstance.RootReference; vilRef = reference.Child("villages"); FirebaseDatabase.DefaultInstance.GetReference("villages").GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { // Handle the error... } else if (task.IsCompleted) { DataSnapshot dataSnapshot = task.Result; // Do something with snapshot... foreach (DataSnapshot s in dataSnapshot.Children) { if (email.Equals(s.Child("email").Value.ToString())) { alreadyHasVil = true; } } } }); BonusChecked = false; FirebaseDatabase.DefaultInstance.GetReference("DailyBonus").GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { // Handle the error... } else if (task.IsCompleted) { DataSnapshot dataSnapshot = task.Result; // Do something with snapshot... foreach (DataSnapshot s in dataSnapshot.Children) { if (email.Equals(s.Child("email").Value.ToString())) { DateTime lastLoggedIn = DateTime.Parse(s.Child("lastBonusTime").Value.ToString()); DateTime minForBonus = lastLoggedIn.AddDays(1); TimeSpan timeNeeded = minForBonus - DateTime.Now; if (timeNeeded < TimeSpan.Zero) { Debug.Log("BONUS AVAILABLE"); //Add money to account bonus = true; //Change last bonus receibed time to now reference.Child("DailyBonus").Child(s.Child("id").Value.ToString()).Child("lastBonusTime").SetValueAsync(DateTime.Now.ToString()); } else { Debug.Log("TIME NEEDED: " + timeNeeded); BonusTime = "Daily Login bonus availabe in : " + timeNeeded.Hours + " Hours and " + timeNeeded.Minutes + " Minutes"; } BonusChecked = true; } } } }); }