• 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 /
  • Help Room /
avatar image
Question by Shamuel · Oct 23, 2016 at 03:19 PM · scripting problemsystemshop

In Game Shop System (Use and Buy Problems) Help!!!!!!!!

the problem is that when a person buys a ship and leaves the tent scene, if reenters have to buy the ship back that's the problem!

what I do is that when the user has enough money and touch the button to buy this disappears and aparace the button to use and sends it to the scene of the other ship, but if you re-enter the store the script is renewed which causes the button use disappear, causing the user have to buy back the ship already bought earlier.

Comment

People who like this

0 Show 4
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 Dibbie · Oct 23, 2016 at 05:04 PM 0
Share

You could either have your shop script DontDestroyOnLoad, or every time the buy button is clicked, depending on the item bought, create a new PlayerPref, every time they enter the shop, then first check your PlayerPrefs and updating the remaining unbought items accordingly.

avatar image Shamuel Dibbie · Oct 23, 2016 at 05:08 PM 0
Share

Thank you very much for your comment, but I could you explain better how to DestroyOnLoad?

avatar image Shamuel Dibbie · Oct 23, 2016 at 05:11 PM 0
Share

function usemodel1() {

     Application.LoadLevel("Space Fever Codes#1");
     }



 function buy(){

             if(gemcount>=500){
             gemremaning = gemcount - shipcost;
             gemcount=gemremaning;
             buying.SetActive(false);
             use.SetActive(true);
             }


here is piece of the script

avatar image Dibbie Shamuel · Oct 27, 2016 at 07:58 PM 0
Share

Essentially, how DontDestoryOnLoad works is, when a new scene is loaded, an object (or script) on the previous scene, will be transfered over to the new scene, its position, children, and everything...

The only problem you may run into, is if the script isnt self-sustrained, and by that I mea it replies on other scripts on other objects, or even other public objects, that now may not exist to function properly.

Before Application.LoadLevel, call DontDestroyOnLoad on the object that has your shop script on it.

So, it would kind of work like:

DontDestroyOnLoad(shopScriptObject.gameObject); Application.LoadLevel("Space Fever Codes#1");

A better alternative in my opinion though, is to create a "inventory" script, that only gets populated when a player buys something, then DontDestroyOnLoad that script, and have your shop script check that script instead, its more organized to me, but either way, works the same.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

90 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Save the Current that what load from playerprefs 0 Answers

Is DateTime working on iOS? 0 Answers

I have a Visual Scripting coin collection problem, can you help? 0 Answers

Creating a shopping cart in Unity scripts problems 0 Answers

C# suddenly no longer building on Linux 0 Answers


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