Question by
GatorOnFire · Sep 27, 2020 at 10:58 PM ·
playerprefsintbool
Why my playerPrefs doesen't work
im making a coin sistem, so when the player hits the coin it deletes and add a value to a UI, the problem is that when i stpo playing and play again the coin appears again. if someone could help me it will be awesome. Here's the code. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class coinscript : MonoBehaviour
{
public GameObject coin;
bool deletecoin;
int value;
public void Update ()
{
PlayerPrefs.SetInt("bool", (deletecoin ? 1 : 0));
}
public void OnTriggerEnter2D(Collider2D other)
{
if(other.CompareTag("Player"))
{
deletecoin = (PlayerPrefs.GetInt("bool") != 1);
Score.scorevalue += 1;
if(deletecoin == true)
{
Destroy(coin);
}
}
}
}
Comment