Y
Y
Yura Mailler2020-01-01 19:41:47
Unity
Yura Mailler, 2020-01-01 19:41:47

How to subtract a number from PlayerPrefs?

Hello! Is it possible to subtract a number from PlayerPrefs?
in my code, by clicking on the button, the number should be subtracted and then loaded
, but the number does not change

public void Chest(){
    	if(money >= 100){
            money-=100;
            PlayerPrefs.SetInt("Money_S", money);
            StartCoroutine(Wait2());
    	}
    	else {
    		NotMoney.SetActive(true);
    		StartCoroutine(Wait4());
    	}
    	
    }

I pret believe you need to delete the key and create a new one thereby changing the number, but can this be done without deleting?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-01-01
@GavriKos

The question is formulated of course so-so - but this code is working. the last money value will be written to Money_S, already from -100. You don't need to delete anything. Maybe you should call Save on playerprefs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question