Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- namespace MobyShop {
- public class myMobyShop : MonoBehaviour {
- public Transform cube;
- public float secTime = 2.0f;
- public float totTime = 0.0f;
- public bool greenCubeIAPOwned = false;
- // Use this for initialization
- void Start () {
- cube = GameObject.Find ("testCube").transform;
- }
- //UPDATE CUBE COLOR
- //Assign cube color based on it (using playerprefs) (see CheckIAP_PurchaseStatus() function below to understand)
- void Update ()
- {
- if (Time.timeSinceLevelLoad > totTime)
- {
- CheckIAP_PurchaseStatus (); //Check status of in app purchase (true/false if player has purchased it)
- totTime = Time.timeSinceLevelLoad + secTime;
- }
- if(cube != null)
- {
- if(!greenCubeIAPOwned)
- {
- cube.transform.GetComponent<Renderer>().material.color = Color.red; // if player has purchased item, turn the cube green
- }
- if(greenCubeIAPOwned)
- {
- cube.transform.GetComponent<Renderer>().material.color = Color.green; // if player has not purchased item (or hasnt restored previous purchases) turn the cube red
- }
- }
- }
- void CheckIAP_PurchaseStatus()
- {
- if( Shop.HasProductBeenBought("green") == true ) {
- greenCubeIAPOwned = true;
- } else {
- Debug.Log("Ignored showing greencube since the user has not bought the greencube purchase");
- }
- }
- //GUI ELEMENTS
- void OnGUI() {
- //Button To PURCHASE ITEM
- if (GUI.Button(new Rect(Screen.width * 0.2f, Screen.height * 0.4f, 150,150),"Make green?"))
- {
- Shop.BuyProduct( "green");
- }
- //Button to RESTORE PURCHASES
- if (GUI.Button(new Rect(Screen.width * 0.2f, Screen.height * 0.8f, 150,150),"Restore\nPurchases")) {
- Shop.RestorePurchases( ( bool ok ) => {
- Debug.Log("RestorePurchases");
- }, (string productIdRestored)=>{
- Debug.Log("Just restored product: " + productIdRestored );
- } );
- }
- //Button to RESTART LEVEL (ensure it doesnt crash)
- if (GUI.Button(new Rect(Screen.width * 0.5f, Screen.height * 0.8f, 150,150),"Restart"))
- {
- Application.LoadLevel (Application.loadedLevel);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement