Hi I am having a problem and that problem is pretty straight I don’t know how to make a shop system and I need a shop system for my game I watched a lot of tutorials but nothing is working for me.
These are the scripts that will be used in the shop system.
these are the scripts that store score
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
public class PlayerHealth : MonoBehaviour
{
public GameObject death;
public int maxHealth = 100;
public static int currentHealth;
public HealthBar healthBar;
public GameObject gameOverPanel;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
healthBar.SetMaxHealth(maxHealth);
}
// Update is called once per frame
void Update()
{
}
public void TakeDamage(int damage)
{
currentHealth -= damage;
healthBar.SetHealth(currentHealth);
if( currentHealth <= 0)
{
Die();
}
}
void Die ()
{
Destroy(gameObject);
audioman.PlaySound ("explosion");
Instantiate(death, transform.position, Quaternion.identity);
PlayerPrefs.SetFloat ("Highscore", PlayerPrefs.GetFloat("Highscore", 0) + ScoreScript.scoreValue);
gameOverPanel.SetActive(true);
ScoreScript.scoreValue = 0;
//script.Score.text = (ScoreScript.scoreValue).ToString();
//Time.timeScale = 0f;
}
}
and this is the script that displays saved score in shop menu ui
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.EventSystems;
public class shop : MonoBehaviour
{
public TMPro.TextMeshProUGUI scoreText;
//public int[,] shopItems = new int[5,5];
//public float Highscore;
//public TMPro.TextMeshProUGUI scoreText;
void Start ()
{
scoreText.text = "Score : " + ((int)PlayerPrefs.GetFloat (“Highscore”)).ToString();
//Items;
/* shopItems[1, 1] = 1;
shopItems[1, 2] = 2;
shopItems[1, 3] = 3;
shopItems[1, 4] = 4;
//Price
shopItems[2, 1] = 100;
shopItems[2, 2] = 2500;
shopItems[2, 3] = 3500;
shopItems[2, 4] = 5000;
//Quantity
shopItems[3, 1] = 0;
shopItems[3, 2] = 0;
shopItems[3, 3] = 0;
shopItems[3, 4] = 0;*/
}
/* public void Buy()
{
GameObject ButtonRef = GameObject.FindGameObjectWithTag(“Event”).GetComponent().currentSelectedGameObject;
if (Highscore >= shopItems[2, ButtonRef.GetComponent<GRIM>().ItemID])
{
Highscore -= shopItems[2, ButtonRef.GetComponent<GRIM>().ItemID];
scoreText.text = "Score : " + ((int)PlayerPrefs.GetFloat ("Highscore")).ToString();
}
}*/
}
These are the scripts I think will be needed in the shop system.
Ok so I have 4 fighter jets that the player can buy. I want these things to be happen when player buy the jet the cost will deduct from the overall score and if the player don’t have enough points it shows a error. But if the player has enough points the player gets the jet and buy button changes to equip button and the most important thing when the player clicks equip after buying the jet plane prefab he/she is using changes to the prefab they equipped. I think this is all the basics of shop system. But how can I do that? Please provide me the code for it and sorry for asking too much this my first time making a shop system and yes the fighter jets are not modifiers they are separate game object prefabs like vehicles.
Thankyou
Thankyou