• 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
0
Question by Ghost-Of-Sparta · Jun 19, 2017 at 01:18 PM · skinshop

In Game Shop

Hello guys what's up i was working in game unity shop and i thought you guys can help me with something,have you ever play color switch or any Ketchapp game? if yes than you saw that in almost everygame there is a shop and i want to make a shop in that way here is my script...yes my scrip its working but i have a problem. when i buy an item it equipts it but i want my money to be -100 and and then to save that i bought that skin can someone help ? :) thank you all

public class Shopmenager : MonoBehaviour { private static int playerMoney; private Text MoneyHud; #region ItemConfig public Image itemIcon; public Text itemCost; public Text itemName; public int buttonIndex; public string ItemName; public string ItemCost; public Sprite ItemIcon; public Sprite BallIcon; public Sprite CointIcon; public Sprite bgWhite; public Sprite noBg; private Image backgroundImg; #endregion

 string skinName = string.Empty;
 private GameObject[] items;
 void Start()
 {
     playerMoney = PlayerPrefs.GetInt("Coints");
     skinName = PlayerPrefs.GetString("PlayerSprite");
     backgroundImg = GetComponent<Image>();
     items = GameObject.FindGameObjectsWithTag("item");
     MoneyHud = GameObject.FindGameObjectWithTag("HudCoins").GetComponent<Text>();
     itemName.text = ItemName;
     itemCost.text = ItemCost;
     itemIcon.sprite = ItemIcon;
 }
 void Update()
 {
     Debug.Log(MoneyHud);
     print(skinName + " " + ItemName);

     if (backgroundImg.sprite.name == bgWhite.name && skinName != ItemName)
     {
         print("Changing "+ItemName);
         
         backgroundImg.sprite = noBg;
     }
 }
 public void On_Click_Button()
 {
     int skin_buyed = 0;
     playerMoney = PlayerPrefs.GetInt("Coints");
     int val = playerMoney - Convert.ToInt32(ItemCost);
      print(playerMoney + " - " + ItemCost + " = " + val);
     if (val >= 0)
     {
         if (canBuy())
         {
             playerMoney = val;
             if (playerMoney <= 0)
             {
                 playerMoney = 0;
             }
             MoneyHud.text = playerMoney.ToString();
         }
         else
         {
             print("You already have this item.");
         }
         switch (buttonIndex)
         {
             case 1:
                 PlayerPrefs.SetString("PlayerSprite", null);
                 PlayerPrefs.SetString("EnemySprite", "Point");
                 break;
             case 2:
                 skin_buyed = PlayerPrefs.GetInt("Skin2");
                 skin_buyed = PlayerPrefs.GetInt("Point2"); 

                 if (skin_buyed == 1)
                 {
                     PlayerPrefs.SetString("PlayerSprite", "Skin3");
                     PlayerPrefs.SetInt("Skin2", 1);
                     itemIcon.sprite = CointIcon;
                     PlayerPrefs.SetString("EnemySprite", "Point3");
                     PlayerPrefs.SetInt("Point2", 1);
                 }
                 else
                 {
                     print("You already buyed this item.");
                 }
                 break;
             case 3:
                 skin_buyed = PlayerPrefs.GetInt("Skin3");
                 skin_buyed = PlayerPrefs.GetInt("Point3");
                 if (skin_buyed == 1)
                 {
                     PlayerPrefs.SetString("PlayerSprite", "Skin3");
                     PlayerPrefs.SetInt("Skin3", 1);
                     itemIcon.sprite = CointIcon;
                     PlayerPrefs.SetString("EnemySprite", "Point3");
                     PlayerPrefs.SetInt("Point3", 1);
                 }
                 else
                 {
                     print("You already buyed this item.");
                 }
             default:
                 break;
         }
         skinName = PlayerPrefs.GetString("PlayerSprite");
         print(skinName);
         foreach(GameObject i in items)
         {
             Image img = i.GetComponent<Image>();
             img.sprite = noBg;
         }
         if (skinName == ItemName)
         {
             backgroundImg.sprite = bgWhite;
             itemIcon.sprite = BallIcon;
             itemName.text = string.Empty;
             itemCost.text = string.Empty;
         }
     }
     else
     {
         print("You dont have enough coins " + ItemCost);
     }
     PlayerPrefs.SetInt("Coints", playerMoney);
 }

 public bool canBuy()
 {  
     

     bool ok = true;
     int skin_buyed = 0;
     switch (buttonIndex)
     {
         case 1:
             
             break;
         case 2:
             skin_buyed = PlayerPrefs.GetInt("Skin2");
             if (skin_buyed == 1)
             {
                 ok = false;
             }
             break;
         case 3:
             skin_buyed = PlayerPrefs.GetInt("Skin3");
             if (skin_buyed == 1)
             {
                 ok = false;
             }
             break;
         default:
             break;
     }
     return ok;
 }

}

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

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

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

108 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 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 do I make a change skin button for my game 2 Answers

Constant internet connection for IAP & Currency purchased through IAP storage 0 Answers

kurt cobain skin/character 0 Answers

Keep shop increased price 1 Answer

How do you make a shop for a clciker game? 1 Answer

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