- Home /
Link real-time data to unity
How can I link or connect or read real time data from a website or database? Basically I have this model where I show it using the unity app, but at the same time, that model have some kind of reading, like the reading of water level and so on, so I'm trying to link those reading(real time data) into the unity app, so even when the reading is changed, the data in the unity app will also change according to the reading.
Sorry, but... what?
What does "real" mean in this context and what's the opposite of it? What API?!?
This question is about to get closed due to insufficient information. Please edit your question ASAP since it's "urgent".
Answer by NaahL · Jun 25, 2020 at 02:25 AM
Are you talking about showing the time on some text?
using UnityEngine;
using System;
using UnityEngine.UI;
public class timer : MonoBehaviour
{
public Text clockText;
void Update()
{
string hour = DateTime.Now.Hour.ToString();
string minute = DateTime.Now.Minute.ToString();
string second = DateTime.Now.Second.ToString();
clockText.text = hour + ":" + minute + ":" + second;
}
}
Sorry to disappoint you, but this is not the "time" i meant, what I meant is like, for example, bitcoin graph, their data is always changing according to the time, and I want to show that data on unity, and follow its data, so whenever the data change on bitcoin, it changes in unity too. But thank you for ur reply :) Idk whether i gave the correct example, but i hope you get what Im saying
Answer by tuinal · Jun 25, 2020 at 03:48 AM
It's no different to doing it in any C# application using System.Net. Below is a generic example ripped off stackoverflow.
How you parse & use the returned data string is up to you, and is usually the time consuming part.
string urlAddress = "http://google.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if (String.IsNullOrWhiteSpace(response.CharacterSet))
readStream = new StreamReader(receiveStream);
else
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
string data = readStream.ReadToEnd();
response.Close();
readStream.Close();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613001651im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Calling Json script and displaying the Images within the script 0 Answers
Alternative to storing data in DB's 2 Answers
Storing Constant data in a mobile game 0 Answers
Unity Web Player Failed To Download Data File 1 Answer
Do you need a realtime data monitor for Unity in your Oculus VR heaset? 0 Answers