0

I need to be able to get the results of database queries run on my Webpage to a SQL Server database regarding user information sent from my game in Unity. I'm a gameplay programmer with significant experience in C#, but I'm at a loss trying to figure out how to make this happen.

The bare minimum I need to figure out is how to send a user/password combination to my web page, check the database for the username, and store it if it does not exist. Finally, sending back a Success or Failure depending on whether the user/password combination already existed.

In Unity I have at my disposal two classes for sending HTTP requests.

1.) https://docs.unity3d.com/ScriptReference/WWW.html

2.) https://docs.unity3d.com/ScriptReference/WWWForm.html

I have basic (very basic) understanding of how web technology works, but the finer details required to make this happen are beyond my current knowledge.

My website is hosted on Azure running ASP.Net MVC. Any help at all or pointers in the right direction would be greatly appreciated.

I have so far been able to get some results back using WWW, but they are meaningless to me and I wouldn't know how to tell if the results of a query were even working (based on the responses). I can of course directly check the database for success, but I need to be able get the results in Unity.

My specific goal:

Send two strings (Username, Password) to an ASP.Net MVC Web app. Have the web app add the two strings to a database if the username is not already in the database. Finally, I need to be able to send the result as a string (Success/Failure) to Unity somehow. This is the part I am most clueless on.

Caboose
  • 453
  • 5
  • 16
  • You forgot UnityWebRequest. First, learn this: https://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-web-app-with-email-confirmation-and-password-reset, then https://www.asp.net/web-api/overview/older-versions/build-restful-apis-with-aspnet-web-api and when done look at WWW or UnityWebRequest again. And you might the most useful information here http://stackoverflow.com/questions/1131425/send-a-file-via-http-post-with-c-sharp?rq=1 – MiningSam Nov 05 '16 at 20:54
  • Please reword your question because I cannot understand what you are trying to do. I have extensive experience with web technology and I may be able to help. – CodingYoshi Nov 05 '16 at 20:57
  • @CodingYoshi I edited the post by adding a clarification at the bottom. It's hard for me to articulate exactly what I'm trying to do because I am so unfamiliar with the web side of software development. That is as close to my specific goal as possible, however. – Caboose Nov 05 '16 at 21:02
  • 1
    @MiningSam Thank you, I will check those out right away. – Caboose Nov 05 '16 at 21:02
  • to achieve this, you send the strings as POST data through an Http request to MVC web app. You do a SELECT query on the database and with a match you return true else you return false and create the Http.response with either succes or failure depending on the result. It is a good practice to create an account with another request for signup purposes – MiningSam Nov 05 '16 at 21:06
  • @MiningSam I can accomplish all of that up to the HTTP.response part, that's the bit I'm unfamiliar with. I suppose that's where I will have to look for my solution. – Caboose Nov 05 '16 at 21:10
  • who will initiate the request? Will Unity initiate the request? – CodingYoshi Nov 05 '16 at 21:11
  • @CodingYoshi Yes. Unity initiates. A player will enter information into the game's UI, then press a confirm button to send the information to the web app. – Caboose Nov 05 '16 at 21:14
  • @Caboose So what is the difficulty you are having? Unity sends key value pair to asp mvc which will check the db and insert if not exists, then it will return a respons to Unity. Unity can do whatever it wants with it. – CodingYoshi Nov 05 '16 at 21:18
  • @CodingYoshi My difficulty is understanding how the asp mvc sends the response, but I think I'm getting closer to understanding. I believe I can use something like to accomplish my goal: Response.AddHeader("Success", Query.Result); – Caboose Nov 05 '16 at 21:26
  • @Caboose MVC allows you to return many result types, JSON or a simple string to name a few. simply return that from the mvc action method. – CodingYoshi Nov 05 '16 at 21:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127456/discussion-between-caboose-and-codingyoshi). – Caboose Nov 05 '16 at 23:47

0 Answers0