I’ve very little to no knowledge and just starting out, im struggling on saving player score via playerprefs, yes I’ve watched plenty of tutorials and read other forum posts but i dont get it!!
Someone gave me a script but i have no ides where to put anything, can someone please help me? Im not good at this at all!!
First script is my resources script
Second is the playerpref script i was given with 3func
using UnityEngine;
using UnityEngine.UI;
public class ResourcesCastle : MonoBehaviour {
public int Coins;
public int Experience;
public int LevelCastle = 1;
public int Wave = 1;
public float Timers = 120f;
public GameObject Cl1;
public GameObject Cl2;
public GameObject Cl3;
public Text CoinsText;
public Text ExperienceText;
public Text LevelCastleText;
public Text WaveText;
public Text Timer;
private float times;
private bool Wave2 = false;
private bool Wave3 = false;
private bool Wave4 = false;
private bool Wave5 = false;
void Start()
{
times = Timers;
}
void Update()
{
WaveUp();
Texts();
Waves();
LvlCastle();
}
void WaveUp()
{
if(Wave5 == true)
{
Wave = 5;
}
if(Wave == 2 && Wave2 == false)
{
gameObject.GetComponent<EnemySpawn>().TimerMax -= 2;
Wave2 = true;
}
if(Wave == 3 && Wave3 == false)
{
gameObject.GetComponent<EnemySpawn>().TimerMax -= 3;
Wave3 = true;
}
if(Wave == 4 && Wave4 == false)
{
gameObject.GetComponent<EnemySpawn>().TimerMin -= 1;
gameObject.GetComponent<EnemySpawn>().TimerMax -= 4;
Wave4 = true;
}
if (Wave == 5 && Wave5 == false)
{
gameObject.GetComponent<EnemySpawn>().TimerMin -= 1;
gameObject.GetComponent<EnemySpawn>().TimerMax -= 5;
Wave5 = true;
}
}
void Texts()
{
CoinsText.text = Coins.ToString();
ExperienceText.text = Experience.ToString();
LevelCastleText.text = LevelCastle.ToString();
WaveText.text = "Wave:" + Wave.ToString();
}
void Waves()
{
times -= Time.deltaTime;
if(times <= 0)
{
Wave += 1;
times = Timers;
}
}
void LvlCastle()
{
if (Cl1.activeInHierarchy == true)
{
LevelCastle = 1;
}
if (Cl2.activeInHierarchy == true)
{
LevelCastle = 2;
}
if (Cl3.activeInHierarchy == true)
{
LevelCastle = 3;
}
}
private int coins;
private string coins_key = "coins";
public void Save()
{
PlayerPrefs.SetInt(coins_key, coins); // 1
PlayerPrefs.Save(); // 2
}
public void Load()
{
if (PlayerPrefs.HasKey(coins_key)) // 3
{
coins = PlayerPrefs.GetInt(coins_key); // 4
}
}
public void Clear()
{
PlayerPrefs.DeleteKey(coins_key); // 5
PlayerPrefs.Save(); // 2
}