0
\$\begingroup\$

I have a database set up on firebase and when i run my game in the unity edtitor and as a standalone exported Windows .exe file, the call gets made correctly to the database and JSON data gets posted correctly. However when I export the exact same project to WEBGL and upload it to my firebase hosting server, the JSON call does not work. Here is my code, could someone please help?

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

 public class GameOverMenu : MonoBehaviour
{
 public InputField nameInputField;

 public void MainMenu()
 {
     SceneManager.LoadScene("Menu");
 }

 public void SubmitScore()
 {
     StartCoroutine(SendScore());
     SceneManager.LoadScene("Menu");
 }
 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {

 }



 public IEnumerator SendScore()
 {
     Scoreboard s = new Scoreboard(nameInputField.text, PlayerPrefs.GetInt("Score"), PlayerPrefs.GetInt("Seed"));
     Dictionary<string, string> headers = new Dictionary<string, string>();
     headers.Add("Content-Type", "application/json");
     Hashtable data = new Hashtable();
     data.Add("name", s.Name);
     data.Add("score", s.Score);
     data.Add("seed", s.Seed);

     UnityHTTP.Request postRequest = new UnityHTTP.Request("post", "https://alexclearythesisgame.firebaseio.com/Scoreboard.json", data);
     postRequest.Send();
     yield return postRequest.isDone;
 }

}
\$\endgroup\$
  • \$\begingroup\$ Check answers.unity.com/questions/898360/… I believe you must configure first some cross domain access, never done that myself. \$\endgroup\$ – arielsan Jul 29 '18 at 16:51
  • \$\begingroup\$ Thank you for your comment . I actually found a solution and will be posting it below . It had something to do with dll files and unity webgl so I had to use the following rest api : github.com/proyecto26/RestClient/blob/master/README.md . Thanks for the comment as it reminded me to update the question \$\endgroup\$ – AC007 Jul 30 '18 at 17:05
0
\$\begingroup\$

I had to use the following free rest api as with the current package I was using , webgl wasn’t transferring the .dlls correctly : https://github.com/proyecto26/RestClient/blob/master/README.md

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.