GameSparks的连接与应用(Unity)--(6)添加成就

GameSparks的连接与应用(Unity)--(6)添加成就



添加一个成就


首先你需要有一个货币,如果没有请看
GameSparks的连接与应用(Unity)--(5)添加货币





添加一个事件





填入代码







var player = Spark.getPlayer();//获得当前玩家
player.addAchievement("Cloud_Achievement");//使玩家获得"Cloud_Achievement"成就


查询货币

需要先登陆,参见

GameSparks的连接与应用(Unity)--(2)玩家登陆




执行获得成就(如果前面设置了成就不重复则只能获得一次成就)




再次查询


unity端添加获得成就(需要先登录)

            new GameSparks.Api.Requests.LogEventRequest()
            .SetEventKey("Award_Achievement")//与Short Code相对应
            .Send((response) =>
            {

                if (!response.HasErrors)
                {
                    Debug.Log("Achivement Awarded Scucessfully...");
                }
                else
                {
                    Debug.Log("Error Awarding Achivement...");
                    Debug.Log(response.HasErrors);
                }
            });


unity端获得账户所有信息

/*可以获得账户的所有细节信息*/
Debug.Log("Fetching Account Details...");
new GameSparks.Api.Requests.AccountDetailsRequest()
    .Send((response) =>
    {

        if (!response.HasErrors)
        {
            Debug.Log("Account Details Found...");
            string playerName = response.DisplayName; // we can get the display name
            List<string> achievementsList = response.Achievements; // we can get a list of achievements earned
            // we can grab all the currency-types into a list //
            List<int> currencyList = new List<int>() 
		{
			int.Parse(response.Currency1.ToString()),
			int.Parse(response.Currency2.ToString()),
			int.Parse(response.Currency3.ToString()),
			int.Parse(response.Currency4.ToString()),
			int.Parse(response.Currency5.ToString()),
			int.Parse(response.Currency6.ToString()),
		};

            Debug.Log ("Display Name: " + playerName);
            Debug.Log("CURRENCY_A: " + response.Currencies.GetLong("CURRENCY_A"));//获得货币CURRENCY_A的数量
            Debug.Log ("Currency1: " + currencyList[0]);
            Debug.Log ("Currency2: " + currencyList[1]);
            Debug.Log ("Currency3: " + currencyList[2]);
            Debug.Log ("Currency4: " + currencyList[3]);
            Debug.Log ("Currency5: " + currencyList[4]);
            Debug.Log ("Currency6: " + currencyList[5]);
        }
        else
        {
            Debug.Log("Error Retrieving Account Details...");
        }
    });




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值