Quantcast
Channel: Questions in topic: "improve"
Viewing all articles
Browse latest Browse all 12

Help returning a variable from this script

$
0
0
I am trying to make a reusable script which retrieves the text from a url. I cannot figure out a way to return the data variable in DataRetrieved to my other script where I am calling the getData function. I am aware they are using void instead of string right now, I reverted it to how it originally was since I couldn't figure it out. The script I am calling: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; using UnityEngine.Networking; public class GetDatabaseInfo : MonoBehaviour { public void getData(string url) { StartCoroutine(GetRequest(url,DataRetrieved)); } private IEnumerator GetRequest(string url,System.Action callback) { UnityWebRequest request = UnityWebRequest.Get(url); yield return request.SendWebRequest(); if(request.isNetworkError || request.isHttpError) { Debug.LogError(request.error + " ...Cannot retrieve database information"); } else { callback(request.downloadHandler.text); } } private string DataRetrieved(string data) { Debug.Log(data); //return data variable here } } The script I am calling it from: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; using UnityEngine.Networking; public class ValidateRegistration : MonoBehaviour { GetDatabaseInfo getDatabaseInfo; private void validate() { string url = "http://localhost:8080/KingdomRushB_Accounts/Accounts.php"; getDatabaseInfo=GameObject.FindGameObjectWithTag("DatabaseInfo").GetComponent(); //(allowing me to call the other script's functions from this script) string data = getDatabaseInfo.getData(url); } How can I get the data variable to return? I would really appreciate if anyone can help me out

Viewing all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>