- Home /
BoolPrefs Problem
Hello evryone
i was searching for boolean player prefs for 2 days and i just dont understand it they say you should make something like this using UnityEngine; using System.Collections;
public class PlayerPrefs2
{
public static void SetBool(string key, bool state)
{
PlayerPrefs.SetInt(key, state ? 1 : 0);
}
public static bool GetBool(string key)
{
int value = PlayerPrefs.GetInt(key);
if (value == 1)
{
return true;
}
else
{
return false;
}
}
}
but there are 2 problems first of all i dont use c# and second i just dont get it i have a coin which the player has to collect and then it shouldnt appear again but i doesnt work i tried everything
if someone could explain me how to do that it would be awesome
thanks in advance skullbeats1
Answer by rocket350 · Oct 04, 2014 at 02:42 PM
Maybe you should try this:
using UnityEngine;
using System.Collections;
public class Plugins : MonoBehaviour {
public GameObject player;
void Start(){
if(PlayerPrefs.HasKey ("ShowCoin") && PlayerPrefs.GetString("ShowCoin") == "false"){
Destroy (gameObject);
}
}
void OnEnterCollision(Collision other){
if(other.gameObject == player){
PlayerPrefs.SetString("ShowCoin", "false");
Destroy(gameObject);
}
}
}
And don't forget to pull the player gameobject into the "player" property in the inspector.
Your answer
Follow this Question
Related Questions
PlayerPrefs Problem crashing with SetBool 2 Answers
PlayerPrefs Help 1 Answer
Creating a Playerpref score system 1 Answer
Playerprefs save player position 3 Answers
Problem with jump bool. Help?! 0 Answers