Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • 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.

Follow this Question

Answers Answers and Comments

106 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

Related Questions

Guiskin custom 0 Answers

error in store,store unity app 0 Answers

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

Skin Morph Problem 2 Answers

Please help how to save last index and load 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