本文介绍了如何使用脚本实现内购功能。
先看下脚本,代码中根据执行过程添加了序号。
using UnityEngine;
using UnityEngine.Purchasing;
using UnityEngine.UI;
namespace Samples.Purchasing.Core.BuyingConsumables
{
public class BuyingConsumables : MonoBehaviour, IStoreListener
{
IStoreController m_StoreController; // The Unity Purchasing system.
//Your products IDs. They should match the ids of your products in your store.
public string coins100ProductId = "com.xxx.unitygame.coins100";
public string coins500ProductId = "com.xxx.unitygame.coins500";
public Text CoinsCountText;
int m_GoldCount;
// 1. 开始入口
void Start()
{
Debug.Log("1. Start begin...");
InitializePurchasing();
UpdateUI();
Debug.Log("1. Start end...");
}
// 2. 初始化内购
void InitializePurchasing()
{
Debug.Log("2. InitializePurchasing begin...");