- Home /
Saving a UI Text Number Multiple Times
I have a UI slider set up and connected to a UI Text so that the text is displaying a number which is reduced if the slider is slid to the left and increased if slid to the right. I have this script for that purpose:
public class SliderUIMoneyTextUpdate : MonoBehaviour
{
string sliderTextString = "500";
public Text sliderMoneyText;
public static int sliderMoneyValue;
public void textUpdate(float textUpdateNumber)
{
sliderTextString = textUpdateNumber.ToString ();
sliderMoneyText.text = sliderTextString;
int.TryParse (sliderTextString, out sliderMoneyValue);
}
}
It is on a canvas and an ok button below the slider. Ok button when clicked sets the canvas as not active. I want to click the ok button and whatever value was set for the slider, i want to save it. The next time its loaded up and moved and the ok button is pressed i want to save that value and add the two saved values together! any ideas how ? Im pressuming its to do with set and get PlayerPrefs or something but dont know how to go about it !
I tried running this and it looks like there's no such thing in the doc as
public "Text" slider$$anonymous$$oneyText;
Answer by siaran · Apr 27, 2015 at 10:24 PM
could do something like
put this at the end of your textUpdate function:
totalMoney += sliderMoneyValue;
PlayerPrefs.SetInt("money", totalMoney);
and on the top of your script
int totalMoney;
void Start(){
totalMoney = PlayerPrefs.GetInt("money", totalMoney);
}
Answer by Surprisejedi · Apr 28, 2015 at 03:17 AM
Oh, first did you make everything public? If you did then make sure you have this
Using UnityEngine.UI;
Using UnityEngine.UI;
Using System.Collections;
Yea sorry I already had that included I just didn't include it in this lol ! Sorry !
Your answer
Follow this Question
Related Questions
Problems in the script for making a text disappear after few seconds 2 Answers
How to change UI button of a particular gameobject to another UI button 0 Answers
Trying to move slider based off percentage of screen 1 Answer
Missing or garbled text in UI.Text 0 Answers
UI Slider, Save Values and Change Them 0 Answers