How To Create A Live Football / Soccer Score App - Unity

This is going to be quite an interesting post if you are a Football / Soccer (oops, I'm not supposed to call it Soccer. Am I? Well, I'm including the word for SEO purpose, you know :P) fan or if you are someone who wanted to know how to create a Football / Soccer Live Scores App. Of course, you can use the same thing as base and create a Live Score Application for any other sport like Cricket / Golf / Tennis etc.

Pre-requisites to develop this Live Score App

Unity Game Engine, which can be downloaded from here.
An active account (demo/pro) on xmlsoccer.com, which will be used to fetch the live data.

Once you have registered and activated your xmlsoccer.com account you will have your own API key. You can find it in the My Account section.

I'm not sure what am I supposed to say about xmlsoccer.com because they are not paying me to write about their site, so I wouldn't bother to write much about them :D
All I can say is, we are going to use the site to get the live data like the league standings, live scores etc.
If you would like to know more about the site, you can simply go through their site and read the Documentation or their wiki where in they have given the Input data formats and everything you need to know about using their site.
Having said that, I won't leave everything to you guys, I mean, obviously why would I even write this post if I had to do that.

Now, coming to the most important part. What would you learn in this tutorial?
Well, you would learn to develop a Unity based App where in you would create a Live Standings app of the Scottish Premier League (since that is the only league data which the website is providing for free). Of course I could have created a Live scorer app instead. But, since no matches are going on right now for me to test the feasibility of the code or the post, I thought it would be better if I created an app which is capable of fetching the League Standings data from the website and displaying them in our app.

The operation, as they call it as, that would fetch the league standings for us is named as GetLeagueStandingsBySeason. This operation expects three parameters as input, viz. ApiKey, league and seasonDateString.
The input data formats of these would look something like
ApiKey: TUQVLZOHZGVWJAQYMLHRLLOZGXIGDVQIZRDAMBRDAAAAAAAAAA (counts to 50 characters / letters)
league: Scottish Premier League
seasonDateString: 14/15, for the 2014/2015 season. 13/14 for the 2013/2014 season etc.

We would use the HTTP Get/Post request to get the league standings xml. This is made possible by WWW or WWWForm class. The url to fetch the 2014/2015 league standings for the Scottish Premier League would look something like

http://www.xmlsoccer.com/FootballDataDemo.asmx/GetLeagueStandingsBySeason?ApiKey=YOUR-API-KEY-HERE&league=Scottish%20Premier%20League&seasonDateString=1415

Clicking on the above link doesn't fetch you the league standing xml, however, because you need a genuine ApiKey for that. Replace the Apikey with your own ApiKey and try it out.

Once you have the xml, you would read the data from the xml using "XmlDocument" class and tabulate the data as per your requirements.

To get started, created a New Unity Project in 2D mode and name it as, say, Live Standing App or perhaps, Live Score App.

Create a New Folder under Assets in the Projects panel and name it as Scenes. Press ctrl+s to save the Scene that you have at the moment and name it as LiveStandingsTable and save it under the Scenes folder you created.

Create Text components for displaying the league table so that they form a table. If you want to learn more about the Unity GUI, I have posted some articles on the same. You can check them out Unity New GUI Tutorial. The table which I have created is as shown in the gif below.

Make Your Own Live Score App - Table Setup
Change the font size and other properties of the Text so that you get the desired result. The configuration which I have used are as in the image below

Make Your Own Live Score App - Text Config
Once you have done this, create a New Folder under the Assets in the Project panel called Scripts. Within this folder add a New C# Script. Name it as GetData. Attach the script to the Main Camera.
Double click on the script to open it and add the below code to it

using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
using System.Xml;
using System.IO;

public class GetData: MonoBehaviour {

 //url to get the league standings xml from
 string urlStandings = "http://www.xmlsoccer.com/FootballDataDemo.asmx/GetLeagueStandingsBySeason?
ApiKey=TUQVLZOHZGVWJAQYMLHRLLOZGXIGDVQIZRDAMBRDMSIFQBKMEN&league=Scottish%20Premier%20League&seasonDateString=1415";
  
 //HTML post url
 string postUrlStandings = "http://www.xmlsoccer.com/FootballDataDemo.asmx/GetLeagueStandingsBySeason"
 
 //input paramters for the form 
 /*
 string apikey = "YOUR APIKEY HERE";
 string league = "Scottish Premier League";
 string season = "1415";
 */


 //References to UI Text elements
 public Text Team;
 public Text Played;
 public Text Won;
 public Text Draw;
 public Text Lost;
 public Text Goals_For;
 public Text Goals_Against;
 public Text Goal_Difference;
 public Text Points;
 
 void Start() {
  //call the getLeagueStandings coroutine
  StartCoroutine(getleagueStandings()); 
 }
 
 //Get the league standings xml and display the data in the league table
 IEnumerator getleagueStandings(){

  //if you want to use the HTTP POST method instead of HTTP GET. use the below code and comment the HTTP GET
  /*
  WWWForm form = new WWWForm();
  form.AddField("ApiKey", "apikey");     
  form.AddField("league", "league");      
  form.AddField("seasonDateString", "season");   
  WWW www = new WWW(postUrlStandings, form);
  
  */


  //HTTP GET
  //create a www object and start downloading the data
  WWW www = new WWW(urlStandings);

  //wait for the request to complete
  yield return www;

  //create a new object of type XmlDocument
  var xml = new XmlDocument();

  //load the xml downloaded from the url specified
   //www.text contains the xml in text format
  xml.LoadXml(www.text);

  //iterate through the xml elements and display them in the Text element
  //we are omitting some xml elements from the downloaded. Hence, some of the numbers in the grandchild nodes are missing.
  //The last element of the xml received is regarding the authentication, which is surplus to requirements. Hence, the loop ends at xml.ChildNodes
[1].ChildNodes.Count-1
  
  for(int j=0; j < xml.ChildNodes[1].ChildNodes.Count-1 ;j++){
   Team.text += "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[0].InnerText;
   Played.text +=  "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[2].InnerText;
   Won.text += "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[5].InnerText;
   Draw.text += "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[6].InnerText;
   Lost.text += "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[7].InnerText;
   Goals_For.text += "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[11].InnerText;
   Goals_Against.text += "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[12].InnerText;
   Goal_Difference.text += "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[13].InnerText;
   Points.text += "\n"+xml.ChildNodes[1].ChildNodes[j].ChildNodes[14].InnerText;
  }

 } 
}

As the code above is well commented. I won't explain it here again. If you have any queries on the same, leave a comment below and we'll try to assist you.

Save the script and return to unity. Now you will notice that the script attached to the Main Camera will expect nine Text components. Drag and drop the respective Text components which you had earlier created.

Make Your Own Live Score App - GetData Script
Save the scene and turn on the internet if it's not on already. Test the scene by pressing the Play button on the top or simply use ctlr+p. You would notice that you now have a Simple Live Standing App which displays the League Standings of the Scottish Premier League.

Make Your Own Live Score App - League Standings

I'm sure you would want to add other features to this, so go ahead. Explore and turn on your thinking cap and be creative.

See you around.
Share on Google+

About Unknown

Sujit Horakeri is a game freak just like any other next door guy you would come across. He is a Web Developer by Profession, Game Developer by Choice.
    Blogger
    Facebook

70 comments:

  1. Can you please make a code axample for getting data from XMLSoccer for a PHP user?

    ReplyDelete
  2. Here I read many new things about how to develop an app for the purpose of soccer score. This is an excellent app for football fans. App Development Firm

    ReplyDelete
  3. how about if u want them to access information offline would it be possible?

    ReplyDelete
  4. Hello, any advice as to how would you do it for Android? I need to create an Android app that will do very similar thing (fetch table data from external API and display it in my app). Any help would be really appreciated.

    ReplyDelete
  5. thanks for the good code, please click here if you want to play online games

    Gclub
    บาคาร่า

    ReplyDelete
  6. Duta doesn't offer football updates, they also offer news updates which are mostly Indian covered headlines and among others.sports scores

    ReplyDelete
  7. Just find a great design and a bag that will set you apart, or show your support for your favorite soccer club.Soccer Blog

    ReplyDelete
  8. Australia conquer Syria 3-2 on aggregate to reserve their spot within an intercontinental playoff against Honduras, who done 4th in North, Central and Caribbean America prior to the USA, in November.
    fifa world cup 2018 match results
    Krestovsky Stadium 2018 Matches

    ReplyDelete
  9. Woah! I'm getting a charge out of the organization/subject of this site. It's clear, yet practical. A huge amount of times it's hard to get that "faultless modify" between incredible comfort and visual intrigue. I should state you've made a not too bad appearing concerning with this

    Fifa world cup 2018 schedule
    Fifa world cup 2018 teams
    Fifa world cup 2018 groups

    ReplyDelete
  10. Realy ! on which platform i can create it. actualy i am not a devloper, but i know some html basic or css.
    Fifa world cup 2018 schedule
    Fifa world cup 2018 teams
    Fifa world cup 2018 groups

    ReplyDelete
  11. Woah! I'm getting a charge out of the organization/subject of this site. It's clear, yet practical. A huge amount of times it's hard to get that "faultless modify" between incredible comfort and visual intrigue. I should state you've made a not too bad appearing concerning with this

    Fifa world cup 2018 schedule
    Fifa world cup 2018 teams
    Fifa world cup 2018 groups

    ReplyDelete
  12. This page gives you a lot of information. Thank you!
    flip diving

    ReplyDelete
  13. I would like to say that this blog really convinced me to do it! Thanks, very good post. http://www.ilovedidierdrogba.co.uk

    ReplyDelete
  14. Hey there, fellow games, I wanted to tell that at this site you will find a great guide on reading someone's text messages without usage of spyware!

    ReplyDelete
  15. Some people say, in order to be the best in soccer, you should have the appropriate gear and equipment. This information is somewhat true. FUN88 Indonesia

    ReplyDelete
  16. This Year 2018 in Russia Fifa World Cup 2018 | ipl schedule 2018 | ipl match list | IPL 2018 | ipl schedule |IPL Players Base Price | Sports News and Updates So Please Stay Tuned and Don’t Miss any Single Update about your favorites Match.

    ReplyDelete
  17. This Year 2018 in Russia Fifa World Cup 2018 | ipl schedule 2018 | ipl match list | IPL 2018 | ipl schedule | IPL Players Base Price | Sports News and Updates So Please Stay Tuned and Don’t Miss any Single Update about your favorites Match.

    ReplyDelete
  18. This Year 2018 in Russia Fifa World Cup 2018 | ipl schedule 2018 | ipl match list | IPL 2018 | ipl schedule | IPL Players Base Price | Sports News and Updates So Please Stay Tuned and Don’t Miss any Single Update about your favorites Match.

    ReplyDelete
  19. That gives off an impression of being fabulous anyway i am still not very beyond any doubt that I like it. At any rate will look much more into it and choose by and by!  NBA Tv Free

    ReplyDelete
  20. This Year 2018 in Russia Fifa World Cup 2018 | ipl schedule 2018 | ipl match list | IPL 2018 | ipl schedule | IPL Players Base Price | Sports News and Updates So Please Stay Tuned and Don’t Miss any Single Update about your favorites Match.

    ReplyDelete
  21. If you want to become your own boss then why don't you learn Digital Marketing Course to boost your website or business in no time.

    ReplyDelete
  22. If you want to become your own boss then why don't you learn Digital Marketing Course to boost your website or business in no time.

    ReplyDelete
  23. If You want to skyrocket your buisness learn Digital marketing course in Delhi and become a leader .

    ReplyDelete
  24. in reality, I'm starting late constantly flabbergasted concerning the basic things served by you. Around four affirmations on this page are obviously the best I've had. Sports Online Coverage


    LIVE SPORTS FOR YOU
    LIVE SPORTS FOR YOU
    LIVE SPORTS FOR YOU
    LIVE SPORTS FOR YOU

    ReplyDelete
  25. www.office.com/setup - Get instant help for MS Office products. We are authorized to support provider in the USA. We will resolve your issues technical issues remotely. http://wwwsetupofficecom.com/setup you can find solution for office.com/setup we have heighly qualified technician for Office com setup
    https://setup-microsoft-office.com- Get instant help for MS Office products. We are authorized to support provider in the USA. We will resolve your issues technical issues remotely. https://setup-microsoft-office.

    ReplyDelete
  26. www.office.com/setup - Get instant help for MS Office products. We are authorized to support provider in the USA. We will resolve your issues technical issues remotely. http://wwwsetupofficecom.com/setup you can find solution for office.com/setup we have heighly qualified technician for Office com setup
    https://setup-microsoft-office.com- Get instant help for MS Office products. We are authorized to support provider in the USA. We will resolve your issues technical issues remotely. https://setup-microsoft-office.

    ReplyDelete
  27. Please keep updating this blog, it's been too long. Great post! We adore this blog and This information is very good.

    SCR888th

    ACE333

    AgentSbobet

    ReplyDelete
  28. And keeping in mind that the ball may appear to be delicate and light when you contact it, when it is going as quick as it does in a round of soccer, it will feel anything other than delicate against your shins! Shin protectors can ensure your legs against agonizing hits and are important paying little respect to which position you play.Best soccer bags

    ReplyDelete
  29. Hello friends.
    I have the free collection of quality ringtones that people want to discuss and install. Hindi ringtone. Bollywood ringtone. and many other music genres here when you visit my homepage: https://ringtonedownload.in/

    Here are the most downloaded ringtones that will not cost you time:

    - Darkside ringtone Download
    - IPL ringtone Download
    - Humnava Mere ringtone Download
    - Majbooriyan ringtone Download
    - Kamariya ringtone Download

    Thank you for listening to my collection. Leave a comment for my post. Thank you!

    ReplyDelete
  30. thank you for ypue post.this is a great post off gaming., I wanted to tell that at this site you will find a great guide on reading someone's text messages without usage of spyware!.ourbdshop text

    ReplyDelete
  31. Download Cric buzz apk
    https://mirrorapkpure.blogspot.com/2018/09/download-cricbuzz-live-cricket-scores.html

    ReplyDelete
  32. If you are looking for more information about flat rate locksmith Las Vegas check that right away. football results

    ReplyDelete
  33. It really eggs on me to lead the game in next level without impediments.

    FullGamePC.com

    ReplyDelete
  34. I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. jadwal bola online

    ReplyDelete
  35. A debt of gratitude is in order for the decent blog. It was extremely valuable for me. I'm glad I discovered this web journal. Much thanks to you for imparting to us,I too dependably discover some new information from your post. best backlinks

    ReplyDelete
  36. When a blind man bears the standard pity those who follow…. Where ignorance is bliss ‘tis folly to be wise…. nhandinhbongda

    ReplyDelete
  37. You should constantly will in general enhance your soccer aptitudes on the grounds that there is continually something you can enhance in your game. Thus, we should investigate primary how to play soccer abilities that you have to ace as soccer player.vao bong88

    ReplyDelete
  38. Much appreciated such a great amount for this data. I need to tell you I agree on a few of the focuses you make here and others might require some further survey, however I can see your perspective. go right here

    ReplyDelete
  39. The LCD Display screen is a screen at the highest point of the console (commonly in the center) which shows a large group of data to you amid diversion play. A case of the data showed is; fundamental amusement insights, framework measurements, VOIP correspondence information and you can even observe what server your companions are playing sure diversions on, for example, World of Warcraft. run3hub.com

    ReplyDelete
  40. Besides, cross breed portable applications incorporate local UI components in those circumstances where it is fundamentally required, as demonstrated by Basecamp's approach towards half and half versatile application development. app dev platform tech pally

    ReplyDelete
  41. Couldn't have enhanced myself. Wonderful and This blog is an untouchable work.
    Poker Indonesia Online

    ReplyDelete
  42. You completed several nice points there. I did a search on the subject and found a good number of persons will consent with your blog. บาคาร่า

    ReplyDelete
  43. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. https://www.pointsbyfifamobile.com/

    ReplyDelete
  44. This is on the grounds that they talk about inspiration, arranging, correspondence and administration separately. baseball trading pins

    ReplyDelete
  45. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. build a website

    ReplyDelete
  46. An agent-based simulation is one in which a number of distinct entities known as "agents" interact. This fits the description of most three-dimensional computer games very well, where the agents are vehicles, characters, fireballs, power dots and so on.https://brawlstarsup.com

    ReplyDelete
  47. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. live football

    ReplyDelete
  48. I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... intanqq

    ReplyDelete
  49. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.
    Spotify premium apk

    ReplyDelete
  50. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. Epictext News

    ReplyDelete
  51. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. Highlight

    ReplyDelete
  52. These come in two options. Either the individual has a rented or owned machine and hosts the game server themselves. The second option is to rent a dedicated game server from a large list of GSP's (game server providers) who for a small monthly charge can host your server for you 24 hours a day and have web based graphic user interfaces in order to start, stop, reinstall, edit configuration files, setup scheduled restarts, install mods and much more. minecraft server hosting

    ReplyDelete
  53. I’ve read a few good stuff here. Definitely worth bookmarking for revisiting. I wonder how much effort you put to make such a fantastic informative site. 토토사이트

    ReplyDelete
  54. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading. 안전놀이터

    ReplyDelete
  55. wow... what a great blog, this writter who wrote this article it's realy a great blogger, this article so inspiring me to be a better person banthang tv

    ReplyDelete
  56. Sometimes, blogging is a bit tiresome specially if you need to update more topics . 먹튀검증 

    ReplyDelete
  57. I was taking a gander at some of your posts on this site and I consider this site is truly informational! Keep setting up.. cricket photos

    ReplyDelete
  58. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here.

    ReplyDelete
  59. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. Soccer Streams

    ReplyDelete
  60. Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. View football highlight

    ReplyDelete
  61. Hello my loved one! I want to say that this post is awesome, nice written and include almost all important information. I would like to peer more posts like this. I’ll right away grab your rss feed as I situs togel terpercaya can’t to find your email subscription hyperlink or e-newsletter service. Do you’ve any? Kindly allow me recognise so that I may subscribe.Thanks.

    ReplyDelete
  62. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. Jadwal Bola Siaran Langsung

    ReplyDelete
  63. See the passing from 5 to three bar foosball method below to set yourself up for an ... just like in gambling poker, a stable defender official source

    ReplyDelete
  64. - learn how to play foosball in much less than 3 mins with brief bullet factors at the authentic guidelines from the international desk soccer visit homepage

    ReplyDelete
  65. Welcome to buy Fifa 19 coins for all FUT series on AOEAH.COM, we are professional and trustworthy store to help every FIFA players enjoy the better game with fast and cheap FUT Coins!Fifa 19 XBOX ONE coins

    ReplyDelete