Hello I have a script in which when You click on a button, If you have enough coin, that button must be unlocked and the wood that is on top of it and acts as kind of price tag disappear. I tried Playerprefs but it didn’t work for me. here is my script in which (wood1) and (wood2) must be disappeared while click on buttons;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MainMenu3 : MonoBehaviour {
public Button WhitePlane;
public Button BluePlane;
public GameObject wood1;
public GameObject wood2;
void Start () {
BluePlane.onClick.AddListener (() => {
character_number=1;
if (UIManager2.coin_score>=1) {
UIManager2.coin_score--;
SceneManager.LoadScene ("Menu2");
}
});
WhitePlane.onClick.AddListener (() => {
character_number=2;
if (UIManager2.coin_score>=2){
UIManager2.coin_score--;
UIManager2.coin_score--;
SceneManager.LoadScene ("Menu2");
}
});
Your question title mentions playerprefs but your code doesn’t have one so I can’t really say what you tried with playerprefs and what’s the problem.
Also, what’s the question then ? You said something doesn’t work and I’m pretty sure it’s not the code that you’ve posted doesn’t work so what you expect us to do here ?
Sorry! I want a brief Tutorial or even a clue for my problem! as I’m new to unity, I didn’t post my code with Playerprefs because I tried Multiple ways but non of them worked. I forgot to Mention character_number variable.here is one of my scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MainMenu3 : MonoBehaviour {
public Button WhitePlane;
public Button BluePlane;
public static int character_number;
public GameObject wood1;
public GameObject wood2;
void Start () {
character_number = PlayerPrefs.GetInt ("Number");
BluePlane.onClick.AddListener (() => {
character_number=1;
if (UIManager2.coin_score>=1) {
UIManager2.coin_score--;
wood1.setactive (false);
SceneManager.LoadScene ("Menu2");
}
});
WhitePlane.onClick.AddListener (() => {
character_number=2;
if (UIManager2.coin_score>=2){
UIManager2.coin_score--;
UIManager2.coin_score--;
wood2.setactive(false);
SceneManager.LoadScene ("Menu2");
}
});
void Update () {
PlayerPrefs.SetInt ("Number", character_number);
}
@lipisis