I’m awarding my players 20 coins if he score 100 points in current level. I’m trying to put this values to Playerprefs so when player play come back to this level, and reach again 100 points, no coins would be given, as he already got the reward. Can’t figure out this.
I have multiple levels & multiple score outcomes. But wouldn’t like player to comeback to LEVEL1 (easy one) and keep getting coins for completing it over and over again.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public GameObject Level1Completed;
public GameObject LevelWindowBackground;
public GameObject burst;
bool levelFinished = false;
public GameObject menuContainer;
public GameObject spawnBallBtn;
public GameObject restartGameBtn;
bool coins100 = false;
// Start is called before the first frame update
void Start()
{
Level1Completed.SetActive(false);
coins100 = (PlayerPrefs.GetInt("coins100") != 1);
}
void Update()
{
if (!GameOver.gameHasEnded && Score.scoreValue <= -50)
{
Invoke("waitforSec", 1f);
GameOver.gameHasEnded = true;
}
if (Score.scoreValue >= 50)
{
LevelWindowBackground.SetActive(true);
burst.SetActive(true);
if (!levelFinished )
{
levelFinished = true;
switch (Score.scoreValue)
{
case 100:
Invoke("threeStars", 1f);
if (!coins100)
{
Debug.Log("Got 20 Coins already");
}
else
{
CoinsCount.coinsValue += 20;
gemsCount.gemsValue += 1;
Tries.tries += 3;
LevelComnpletedCoins.CoinsWon = 20;
LevelCompletedGems.GemsWon = 1;
coins100 = true;
PlayerPrefs.SetInt("coins100", (coins100 ? 1 : 0));
}
break;
}
}