In game sprite store

I am trying to create an in-game store, where players can buy skins (sprites) from the in-game currency (I already added) However I do not know how to change the sprites and how to give the players an option to save their progress from the start of the game.

Can someone please help?

1 Like

was this resolved?
great idea btw

Hello!

I did create a sprite store script, but it did not work quite well in this game, but I have created another game and have added a better version of the script that both saves the game when they close it and update it.

(It is really long and a bit tedious, but there are not bugs or issues in it)

Also the player does not need to buy any ball again, he simply sets it

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

public class BallStoreManager : MonoBehaviour {
	public Text text;
    public Text redtext;
    public Text greentext;
    public Text bluetext;
    public Text orangetext;
    public Text pinktext;
    public Text purpletext;
    public Text whitetext;
    public Text blacktext;

    public static float coins = 0;
    public static float redcost = 25;
	public static float greencost = 50;
	public static float blackcost = 75;
	public static float bluecost = 100;
	public static float orange = 150;
	public static float pink = 200;
	public static float purple = 275;
	public static float whitecost = 325;

	public static bool boughtRedBall = false;
	public static bool boughtGreenBall = false;
	public static bool boughtblackBall = false;
	public static bool boughtblueBall = false;
	public static bool boughtorangeball = false;
	public static bool boughtpinkball = false;
	public static bool boughtpurple = false;
	public static bool boughtwhite = false;

   
	public void adtext() {
	text.text = "Watch an ad for 25 coins!";
	}
	

	public void adcoins ()
	{
	PlayerPrefs.SetFloat("coins", coins+15);
	Debug.Log("shouldwrk");
	}
	public void AddCurrency0 (){
	PlayerPrefs.SetFloat("coins", coins+1);
	}

	

	public void BuyRedBall ()
	{
        if (PlayerPrefs.GetFloat("coins") > 25 && PlayerPrefs.GetFloat("redcost", redcost) > 24) {
            redtext.text = "Buy Red Ball for 25 Coins!";  
            PlayerPrefs.SetFloat("coins", coins -= 25);
			PlayerPrefs.SetFloat("redcost",redcost -= 25);
			boughtRedBall = true;
			boughtblackBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;

			Debug.Log("boughtred");
		}
        if (PlayerPrefs.GetFloat("redcost", redcost) < 1) {
		boughtRedBall = true;
			boughtblackBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;
            redtext.text = "Set Red Ball";
		Debug.Log("setred");
		}
        else if (PlayerPrefs.GetFloat("coins") < 25) {
			redtext.text = "Not enough money";
			}
 	}
	public void BuyGreenBall ()
	{
       
        if (PlayerPrefs.GetFloat("coins") > greencost && PlayerPrefs.GetFloat("greencost", greencost) > 49) {
            greentext.text = "Buy Green Ball for 50 coins";
			PlayerPrefs.SetFloat("coins", coins -= 50);
			PlayerPrefs.SetFloat("greencost", greencost -= 50);
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = true;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;

			Debug.Log("boughtgreen");
		}
        if (PlayerPrefs.GetFloat("greencost", greencost) < 1){
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = true;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;
            greentext.text = "Set Green Ball";
		Debug.Log("setgreen");
		}
        else if (PlayerPrefs.GetFloat("coins") < 50) {
            greentext.text = "Not enough money";
}
 	}
	public void BuyblackBall ()
	{
        
        if (PlayerPrefs.GetFloat("coins") > blackcost && PlayerPrefs.GetFloat("blackcost", blackcost) > 74) {
            blacktext.text = "Buy Black Ball for 75 coins!";
			PlayerPrefs.SetFloat("coins", coins -= 75);
			PlayerPrefs.SetFloat("blackcost", blackcost -= 75);
			boughtblackBall = true;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;
           
			Debug.Log("boughtblack");
		}
        if (PlayerPrefs.GetFloat("blackcost", blackcost) < 1) {
            
			boughtblackBall = true;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;
            blacktext.text = "Set Black Ball";
        }else if (PlayerPrefs.GetFloat("coins") < 75)
        {
            blacktext.text = "Not enough money - it costs 75 coins";

        }

 	}
	public void BuyblueBall ()
	{
        
        if (PlayerPrefs.GetFloat("coins") > bluecost && PlayerPrefs.GetFloat("bluecost", bluecost) > 99) {
            bluetext.text = "Buy Blue Ball for 100 coins!";
			PlayerPrefs.SetFloat("coins", coins -= 100);
			PlayerPrefs.SetFloat("bluecost", bluecost -= 100);
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = true;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;
			Debug.Log("boughtblack");
           
		}
        if (PlayerPrefs.GetFloat("bluecost", bluecost) < 1) {
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = true;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;
            bluetext.text = "Set Blue Ball";
		}
        else if (PlayerPrefs.GetFloat("coins") < 100) {
            bluetext.text = "Not enough money - it costs 100 coins";

		}
 	}
	public void BuyorangeBall ()
	{
       
        if (PlayerPrefs.GetFloat("coins") > orange && PlayerPrefs.GetFloat("orange", orange) > 149) {
            orangetext.text = "Buy Orange Ball for 150 coins!";
			PlayerPrefs.SetFloat("coins", coins -= 150);
			PlayerPrefs.SetFloat("orange", orange -= 150);
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtorangeball = true;
           
			
        }if (PlayerPrefs.GetFloat("orange", orange) < 1) {
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = true;
            orangetext.text = "Set Orange Ball";

		}
        else if (PlayerPrefs.GetFloat("coins") < 150) {
            orangetext.text = "Not enough money - it costs 150 coins";

		}
 	}
	public void BuypinkBall ()
	{
        
        if (PlayerPrefs.GetFloat("coins") > pink && PlayerPrefs.GetFloat("pink", pink) >199) {
            pinktext.text = "Buy Pink Ball for 200 coins!";
			PlayerPrefs.SetFloat("coins", coins -= 200);
			PlayerPrefs.SetFloat("pink", pink -= 200);
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = true;
			boughtorangeball = false;

			Debug.Log("boughtblack");
		}
        else if (PlayerPrefs.GetFloat("pink", pink) < 1) {
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = true;
			boughtpurple = false;
			boughtwhite = false;
			boughtorangeball = false;
            pinktext.text = "Set Pink Ball";
		}
            else if (PlayerPrefs.GetFloat("coins") < 200) {
            pinktext.text = "Not enough money - it costs 200 coins";

		}
 	}
	public void Buypurple ()
	{
        
        if (PlayerPrefs.GetFloat("coins") > purple && PlayerPrefs.GetFloat("purple", purple) > 274) {
            purpletext.text = "Buy Purple Ball for 275 coins";
			PlayerPrefs.SetFloat("coins", coins -= 275);
			PlayerPrefs.SetFloat("purple", purple -= 275);
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = true;
			boughtorangeball = false;

			Debug.Log("boughta");
		}
        else if (PlayerPrefs.GetFloat("purple", purple) < 1) {
		boughtpurple = true;
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtwhite = false;
			boughtorangeball = false;
            purpletext.text = "Set Purple Ball";
		}
        else if (PlayerPrefs.GetFloat("coins") < 275) {
            purpletext.text = "Not enough money - It costs 275 coins";

		}
 	}
	public void Buywhite ()
    {
        
        if (PlayerPrefs.GetFloat("coins") > whitecost && PlayerPrefs.GetFloat("whitecost", whitecost) > 324) {
            whitetext.text = "Buy White Ball for 325 coins!";
			PlayerPrefs.SetFloat("coins", coins -= 325);
			PlayerPrefs.SetFloat("whitecost", whitecost -= 325);
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = true;
			boughtorangeball = false;
			Debug.Log("boughta");

		}
        else if (PlayerPrefs.GetFloat("whitecost", whitecost) < 1) {
			boughtblackBall = false;
			boughtRedBall = false;
			boughtGreenBall = false;
			boughtblueBall = false;
			boughtpinkball = false;
			boughtpurple = false;
			boughtwhite = true;
			boughtorangeball = false;
            whitetext.text = "Set White Ball";
		}
        else if (PlayerPrefs.GetFloat("coins") < 325) {
            whitetext.text = "Not enough money - It costs 325 coins";

		}
 	}
	private void Update()
	{
        text.text = "You Have " + PlayerPrefs.GetFloat("coins").ToString() + " coins!";

	}

}

Privacy & Terms