• 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
0
Question by Vinyle · Aug 02, 2018 at 11:44 PM · shop

CharacterShop problem,Charactershop problem

Hi, i am currently working on a shop for my platformer, and everything works except the unlock button does not turn interactable when i have enough money. I have made a reset button that resets all playerprefs. If i have enough money and THEN press reset, everythings works perfectly. But the reset button are not meant to be in the final version. But if i press reset before i get enough money the button does not work. So i need a way to maybe refresh the scene and check if i have more money than the price of the item? Any suggestion is appriciated and if you have more questions just ask:)

Here the code:

using System.Collections; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;

public class ObjectBuyer : MonoBehaviour {

 public static int score;

 int isObjectSold;

 public int objectPrice;

 public Text text;
 public Text ObjectPrice;

 public Button buyButton;

 public Button selectButton;

 // Use this for initialization
 void Start()
 {

     score = PlayerPrefs.GetInt("PlayerCurrentScore");
     score = PlayerPrefs.GetInt("IsObjectSold");


 }

 // Update is called once per frame
 void Update()
 {


     isObjectSold = PlayerPrefs.GetInt("IsObjectSold");

     if (score >= objectPrice && isObjectSold == 0)
         buyButton.interactable = true;
     else
         buyButton.interactable = false;

     if (isObjectSold == 0)
         selectButton.interactable = false;



 }

 public void buyObject()
 {
     ScoreManager.AddPoints(-objectPrice);
     PlayerPrefs.SetInt("IsObjectSold", 1);
     buyButton.interactable = false;
     selectButton.interactable = true;
 }

 public void exitShop()
 {
     PlayerPrefs.SetInt("Score", score);
     SceneManager.LoadScene("Main Menu");
 }

 public void resetPlayerPrefs()
 {
     score = PlayerPrefs.GetInt("PlayerCurrentScore");
     buyButton.interactable = true;
     //objectPrice.text = "Unlock";
     PlayerPrefs.DeleteAll();

 }

},

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
0

Answer by Vinyle · Aug 04, 2018 at 08:01 PM

Figured out the solution myself. All i took was this little code in the update function:

     if (isObjectSold != 0)
         PlayerPrefs.SetInt("IsObjectSold", 1);
Comment
Add comment · 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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

88 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

Related Questions

In-game Shop / Market/ Buying / inventory system? 3 Answers

coins go to 0 1 Answer

Swipe to place order in ShopScrollList (prefabs, object pooling, instantiating) 0 Answers

How to make a for loop display inventory correctly? 0 Answers

Shop no longer working on level reset 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges