Displaying REAL-WORLD Weather in Unity (using REST APIs)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I hope this will be a helpful resource! Here's a link to the project's GitHub repository if you want to check it out: https://github.com/PolyMarsDev/Real-World-Weather

👍︎︎ 4 👤︎︎ u/PocketMars 📅︎︎ Nov 27 2019 🗫︎ replies

Now this is very cool. Just adding to my dream of one day making a Bethesda style RPG.

👍︎︎ 3 👤︎︎ u/ArmanDoesStuff 📅︎︎ Nov 27 2019 🗫︎ replies

This is really interesting! Thanks!

👍︎︎ 2 👤︎︎ u/MrMeloMan 📅︎︎ Nov 27 2019 🗫︎ replies
Captions
welcome back I change my name from pocket marks to poly Mars and you probably don't care so I'll talk about why at the end of the video recently I've been experimenting with using REST API immunity if you don't know what a REST API is it's just a web service that can receive HTTP requests and return a message for example with the open notify API you can request their current location of the International Space Station and it will return a JSON file with the ISS as current latitude and longitude by using these api's in combination with unities unity web request function there are a lot of interesting ways you can use these web services in your projects for example I actually use the open notify API to make an app for a competition that requests the current location of the International Space Station and maps it to a globe I have a lot of different ideas for projects using REST API is that I want to create but I figured I'd start with something simple I spent the past few days creating a small unity project that displays the current real world weather in your location in real time I think this is a mechanic that could be interesting in a few different types of games in a farming game like starting valley for example players could check the real-life forecast and wait for a rainy day to plant their crops so in this video I'm going to explain how exactly I created this system what I had to do can be divided into three steps I had to get the users current location use the location to request the current weather of the user and activate and deactivate different game objects in the scene based on the current weather information so you get the weather I planned to use the dark sky weather API which can return any of these values for the weather so I started by grouping these into broader categories and making simple effects for each type of weather in unity using particle systems and sprites made with I also might have gotten a little carried away and made an animated a player that follows the mouse cursor dark sky takes a lotta - and longitude as an input when returning the current weather I thought it would be able to use unities location service to easily get the player's latitude and longitude but I kind of overlooked the fact that it only worked on mobile devices so I wasted a lot of time trying to figure out why it wasn't working I ended up having to use two additional api's to get the current location of the user first I use what is my IP address come to get the players IP address to do this I basically just run a CO routine on startup that downloads the IP address from the URL it waits for the text to be downloaded and if it fails stops a function but if it works stores it in a string then I use IP API comm to get the latitude and longitude of the IP address this process is pretty similar to what I had to do to get the IP but it's a little more involved since the API returns a JSON that I need to parse in my script I created a serializable class called location info that is structured identically to the JSON file that IP API comm returns if a value returning the JSON is in quotes I make it a string and if it isn't I make it a float then after I get the IP address I run a KO teen that downloads a JSON with the location information from IP api using the IP [Music] if it works I use unique JSON utility class to create an object called info from the JSON data with the structure of the location info object now I can use info dot lat and info dot long to get the latitude and longitude of the player and now that I have access to the player's longitude and latitude I made a script that uses it to get the current weather of the player the process is pretty similar to getting the players location but the JSON file returned by the dark sky API is a little more complex this JSON file has multiple layers but since the only value we need to access is in the currently object I only need to create a class for the outermost level and the currently object within that level from the get location script I call a function in the weather data script that sets the values of the latitude and longitude to their values in the get location script and activates a timer that will run a code team to request the weather information every five minutes dark skies API allows for a thousand free requests per day so I can make a lot of requests but I wouldn't recommend updating the weather any more frequently than that then once again the co-routine downloads a JSON from dark sky using the latitude and longitude and an API key then I use JSON utility again to create an object called info from the JSON and I can access the values from the JSON using the object for example to get the temperature I use info currently temperature to get the weather however we'll be using the icon string which displays a machine-readable summary of the weather I made a simple state manager that activates the right weather game object for the current value of the icon and deactivates any other weather game objects that might be active [Music] I also display a longer and more human readable description of the weather which is found in the summary string in the bottom left corner and dark sky requires that you give them credit so I put that in the bottom right corner and now that it's done I thought I'd show it in action so if I go outside it's looking pretty sunny outside then if I hop back inside and open the project it accurately shows that it is sunny if you want to try out the project for yourself you can find the link to its github repository in the description if you want to use it you'll need to provide your own dark sky API key which you can get for free by registering on their website and of course if you like this video consider subscribing because I plan to do more projects using REST API in unity and also just other unity experiments in general if you have any feedback or suggestions for future content please let me know in the comments that's all so before I end the video I guess I'll talk about why I changed my name I wanted to change my name eventually because there's this board game and I figured I'm better off changing it sooner rather than later and I also wanted to make an icon that was a little more unique than my old icon which is just a clipart of Mars with a gradient so I made this and I like this icon more because it actually has colors similar to the colors of Mars and it uses an art style that I've used in a few of my games instead of being generic clipart so as a result of this change my Twitter github and interested IO links have changed but I've updated all my videos with the new links that's all I wanted to address so thanks for watching and I'll see you in the next video [Music] you
Info
Channel: PolyMars
Views: 75,264
Rating: undefined out of 5
Keywords: real, world, realtime, actual, real life, weather, temperature, unity, unity3d, the actual weather, real life weather, current, devlog, tutorial, polymars, poly, mars, rest apis, apis, web services, rest apis in unity, json, unitywebrequest, www, tech demo, remake, made with unity, indie dev, gamedev, c#, c sharp
Id: PnCtUemkqZs
Channel Id: undefined
Length: 7min 32sec (452 seconds)
Published: Tue Nov 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.