okay so I’m trying to get Unity to post data to my MongoDB realm with the SDK. My game has a mini game inside of it, and when the mini game ends (timeleft == 0), it should pull the data from that attempt (score, etc) and send it to the database.
However, instead of doing this, it’s pausing the game (not freezing or slowing, literally pausing, as if I clicked the pause button). It’s also not being received by my database.
Code below:
using System;
using UnityEngine;
using Realms;
using Realms.Sync;
using MongoDB.Bson;
public class DBcontrol : MonoBehaviour
{
private int points;
private int GameOver;
private float ticktock;
/* public App app;
public User user;
public PartitionSyncConfiguration config;
public Realm realm;*/
public static DBcontrol Instance;
public string RealmAppId = "PRIVATE INFO";
private Realm _realm;
private App _realmApp;
private User _realmUser;
void Awake()
{
DontDestroyOnLoad(gameObject);
Instance = this;
}
void OnEnable(){
_realm = Realm.GetInstance();
}
void OnDisable()
{
if (_realm != null)
{
_realm.Dispose();
}
}
void Start()
{
_realmApp = App.Create(new Realms.Sync.AppConfiguration(RealmAppId));
points = GameObject.Find("FPlayer").GetComponent<RightClickSaveAs>().scorevar;
GameOver = GameObject.Find("FPlayer").GetComponent<RightClickSaveAs>().idle;
ticktock = GameObject.Find("FPlayer").GetComponent<RightClickSaveAs>().timeLeft;
/* app = http://Realms.Sync.App.Create("private token");
user = new http://Realms.Sync.App.LogInAsync(Credentials.Anonymous());
config = new Realms.Sync.PartitionSyncConfiguration("ETH_inbox", user);
realm = Realms.Sync.GetInstanceAsync(config);*/
}
void Update()
{
int GameOver = GameObject.Find("FPlayer").GetComponent<RightClickSaveAs>().idle;
float ticktock = GameObject.Find("FPlayer").GetComponent<RightClickSaveAs>().timeLeft;
string date = http://System.DateTime.Now.ToString("http://dd.MM.yyyy");
string time = http://System.DateTime.Now.ToString("http://HH.mm.ss");
if (ticktock <= 0)
{
_playerprofile = new DataBlueprint
(
"test.eth", GameObject.Find("FPlayer").GetComponent<RightClickSaveAs>().scorevar,
"@test",
("[" + date + "], <" + time + ">"),
"69420gm",
42069
);
_realm.Write(() =>
{
_realm.Add(_playerProfile);
});
Debug.Log("successfully recorded attempt");
}
}
//}