---
title: 'instanceObj'
disqus: hackmd
tags: 'so'
---
## **Instancify Item**
How instancify an item and obtain its unique Item ID.
Click Item.

點擊NewItemInstanceBtn,實例化物品。 Click NewItemInstanceBtn to instacify an item.

p.s. Instancing an item means binding it with the user’s account. A common way is to make it a player’s personal game data. The example in the picture demonstrates how that account gets an Item ID from CallBack.
```
C#
using UnityEngine;
using System.Collections;
public class Sample_GetItemClass : MonoBehaviour {
/*******************************************************************
* Copyright © 2022 SPKITA Game Cloud. All Rights Reserved
*
*******************************************************************/
//enter the gguid shown in the developer backstage here
private const string gguid = "";
//enter the item iguid shown in the developer backstage here
private const string item_iguid = "";
//enter the verification shown in the developer backstage here
byte[] certificate = {};
//declare CloudGame and this Class will be in charge of the communication with Cloud Server
public CloudGame ag = null;
string userAcc; //user’s account
string userPwd; //user’s password
void Start()
{
CloudSystem.UnityEnvironment();
CloudSystem.ServerProvider("sgc-api-us.spkita.com"); // set the server
}
void OnApplicationQuit()
{
//When the program is closed, the user’s account will not be logged out. Here we can add a mechanism that allows automatic logging out.
if(ag!=null) ag.Dispose();
}
public void LoginBtnClick()
{
userAcc = login_input_acc.text;
userPwd = login_input_pwd.text;
//the parameters needed when logging in, which are (account, password, gguid, certificate)
ag = new CloudGame(userAcc, userPwd, gguid, certificate);
//designate the way of management and start the detection on whether the connection is successful
ag.onCompletion += CloudLaunch;
ag.UnityLaunch();
}
/*******************************************************************
// After CloudGame finishes its execution, in CallBack there will be a message about whether the login is successful.
// When the code is 0, the login succeeds and when the code is not 0, the login fails.
// refer the errors in login to Error Code
//
*******************************************************************/
void CloudLaunch(int code, CloudGame game)
{
if (code == 0)
{
Debug.Log("Login Success! My poid : " + ag.poid + " NickName : " + ag.nickname);
}
else
{
Debug.LogWarning("Login Fail! Code : " + code);
}
}
/*******************************************************************
* 實例化物品 Instancify an item
*******************************************************************/
public void NewItemInstanceBtn()
{
CloudItem.NewItemInstance(ag, item_iguid, CB_NewItemInstance, null);
}
/*******************************************************************
* code為0表示實例化成功 code非0表示實例化失敗 When the code is 0, the instancing succeeds and when the code is not 0, the instancing fails.
*******************************************************************/
void CB_NewItemInstance(int code, object data, object token)
{
if (code == 0)
{
_itemid = data.ToString(); // Record my instacified ID to use it when writing in data in the future.
item_MsgText.text += "ItemInstance Success! \nItem ID = " + data + "\n";
}
else
{
item_MsgText.text += "ItemInstance Fail! Code : " + code + " \n";
}
}
}
```