- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Alp-Giray-Savrum · Sep 03, 2014 at 06:48 AM ·
textplayerprefsstringtextmeshglobalvariables
If Statements with PlayerPrefs
Hello guys, I need to set game options using PlayerPrefs but i don't know how to write if statements. I wrote an example code
#pragma strict
var playTypeString : String;
function Update () {
var text = gameObject.GetComponent(TextMesh);
text.text = playTypeString.ToString();
if(PlayerPrefs.GetString(playerType,"sphere")){
playTypeString = "sphere";
}
if(PlayerPrefs.GetString(playerType,"stick")){
playTypeString = "stick";
}
if(PlayerPrefs.GetString(playerType,"plus")){
playTypeString = "plus";
}
}
But as i said i got syntax error. What can i do ?
Comment
Best Answer
Answer by zharik86 · Sep 03, 2014 at 06:59 AM
Where are you define the playerType variable. I will a little rewrite your code:
#pragma strict
var playTypeString : String;
function Update () {
//Get from PlayerPref variable by name "playerType"
var playerType: String = PlayerPrefs.GetString("playerType", "");
if(playerType =="sphere") {
playTypeString = "sphere";
} else if(playerType == "stick") {
playTypeString = "stick";
} else if(playerType == "plus") {
playTypeString = "plus";
}
var text = gameObject.GetComponent(TextMesh);
text.text = playTypeString.ToString();
}
I hope that it will help you.
Your answer
Follow this Question
Related Questions
Change the content of a Text Mesh 1 Answer
TextMeshPro " != " not working 1 Answer
Text Mesh Scripting 1 Answer
C# - how do I get the number of lines in a TextMesh 2 Answers