Sign In Register

How can we help you today?

Start a new topic
Answered

GameSparks, Unity and C# examples

Hi there!


Just wanted to say that so far I'm loving GameSparks. It's blazing fast, simple to setup and use. However, I do have some issues regarding C# and Unity. The documentation seriously lacks examples for various languages.


For instance, in SparkPlayer document, it says


var userName = Spark.getPlayer().getDisplayName(); which is totally fine. I assume this code example is for CloudCode editor.

However, I would like to see examples of how to get the data from Unity (C# specifically).


I've come up with the following code to get the player displayName and I'm not sure whether I should be doing it like that.

This code seems a bit off to me, but lacking experience and knowledge in this area, I cannot say for sure.

Interestingly enough, if I type Game.Instance.DisplayName = response["displayName"].ToString() doesn't do anything, so I have to do some voodoo with new object.


void Login()
{
         Debug.Log("[GameSparks]: Logging in...");

         GameSparksApi.authenticationRequest(userName, password).sendAsync(delegate(IDictionary<string,object> response)
         {
              Debug.Log("[GameSparks]: authentication response="+response["@class"]);
              object value = new object();
              response.TryGetValue("displayName", out value);
              Game.Instance.Player.DisplayName = value.ToString();
              Debug.Log("[GameSparks]: authentication "+(GameSparksApi.isAuthenticated()?"succeeded.":"failed."));
         });
}


If there is a better place to paste code and discuss it, please let me know and I will in the future.

Also, I would assume that the majority of your customers have little to no experience in back-end and that's why they're using GameSparks in the first place - along with the insane amount of time saved not to mention budget.


Thanks a ton!


Best Answer

Hi Pavao,


We have a great set of Unity tutorials which will get you up and running with the basics quickly, they're located here. You'll also find our Client - API reference extremely useful to you, it contains examples in multiple languages, you can find it here.


Thanks,

Liam

          



1 Comment

Answer

Hi Pavao,


We have a great set of Unity tutorials which will get you up and running with the basics quickly, they're located here. You'll also find our Client - API reference extremely useful to you, it contains examples in multiple languages, you can find it here.


Thanks,

Liam