using System.Net.Http; using UnityEngine; using UnityEngine.UI; public class APIHelper : MonoBehaviour { [Header("Request")] public string cityName; public string ownKey; [Header("Sliders")] public Slider master; public Slider rain; public Slider wind; public Slider fog; public Slider lightning; private WeatherAPI_Response weatherResponse; private void Awake() { master = GameObject.Find("MasterSlider").GetComponent(); rain = GameObject.Find("RainSlider").GetComponent(); wind = GameObject.Find("WindSlider").GetComponent(); fog = GameObject.Find("FogSlider").GetComponent(); lightning = GameObject.Find("LightningSlider").GetComponent(); } private void Start() { GetData(cityName, ownKey); master.value = 1; } async void GetData(string city, string apiKey) { string API_URL = "http://localhost:8080/weather?city=" + city + "&apiKey=" + apiKey; using (var httpClient = new HttpClient()) { var response = await httpClient.GetAsync(API_URL); if (response.IsSuccessStatusCode) { weatherResponse = JsonUtility.FromJson(await response.Content.ReadAsStringAsync()); ChangeValuesInGame(weatherResponse); } else { Debug.Log(response.ReasonPhrase); } } } void ChangeValuesInGame(WeatherAPI_Response weather) { rain.value = weather.rain; wind.value = weather.wind; fog.value = weather.fog; lightning.value = weather. Lightning; } }