Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by echoespf · Jun 22, 2012 at 09:57 AM · playerprefsprime31storekit

PlayerPrefs to Unlock Object question

I'm relatively new to Unity and have been building an iPhone app for quite some time. I want to have in app purchases for certain gameobjects and I'm wondering how I would go about doing that. Everything I read is I need to use PlayerPrefs but I can't find a good tutorial. I need it to work with Prime31's Storekit plugin which I have up and running. I can easily make purchases with this great plugin but my noobish nature isn't allowing me to figure out how to assign this to an object to lock and unlock it once purchase is successful.

Thanks to anyone that can help me or point me to a good tutorial which I can't find for the life of me!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by whydoidoit · Jun 22, 2012 at 10:04 AM

How about something like this:

On purchase:

   PlayerPrefs.SetInt("Bought_" +itemName, 1);

To check for purchase:

   if(PlayerPrefs.HasKey("Bought_" + itemName)) {
      //Item was purchased
   }
Comment
Add comment · Show 40 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image echoespf · Jun 22, 2012 at 07:59 PM 0
Share

I don't mean to be dense but where would I put this code? Sorry. Still learning!

avatar image whydoidoit · Jun 22, 2012 at 08:38 PM 0
Share

So put the On Purchase code where you buy the item and the other code anywhere where you want to know if the item has been purchased...

avatar image echoespf · Jun 22, 2012 at 08:43 PM 0
Share

So the only code I have setup right now that pertains to this issue is the in app purchase plugin which tests fine. Let's say I have a cube that I want to unlock in a particular scene. Do I place the on purchase on the cube and the item was purchased on the scene? Thanks for your help. I appreciate it.

avatar image whydoidoit · Jun 22, 2012 at 08:51 PM 0
Share

Yes - so i your store unlock you put that On purchase code then if you you want the item to only appear if it was purchased add a script with this in it to the item in your scene:

     var itemName : String;

     void Awake() {
          if(!PlayerPrefs.Has$$anonymous$$ey("Bought_" + itemName)) {
             Destroy(gameObject);
         }
     }

You can put that same script on each item that can be bought and set the itemName in the inspector to match the name of the item when you buy it.

avatar image whydoidoit · Jun 22, 2012 at 08:52 PM 0
Share

You would have to reload your scene after a purchase with that code - if you want something cleverer than that I can give it a go...

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to bind Prime31 ios storekit plugin with GUIText elements? 1 Answer

Problem with Prime31 StoreKit plugin 0 Answers

Storekit Product details stopped showing ? 0 Answers

Prime31 StoreKit Question 0 Answers

Prime31 Storekit purchaseSuccessfulEvent claims to have receipt, but I can't find it. How do I find the receipt? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges