- Home /
Split string from PlayePrefs
Hello,
I want to make a game timer based on the string value from the PlayerPrefs-class.
void Start(){
string[] time = PlayerPrefs.GetString("EventDuration", "5:00").Split(":");
int min = int.Parse(time[0]);
int sec = int.Parse(time[1]);
eventDuration = min*60f + sec;
}
void Update(){
eventDuration -= Time.deltaTime;
if(eventDuration <= 0)
GameOver();
}
But I get an error: The best overloaded method match for `string.Split(params char[])' has some invalid arguments
Comment
Best Answer
Answer by Brocccoli · Mar 23, 2016 at 06:53 PM
You're using a string because you enclosed the colon in double quotes.
If you change the .Split call to
string[] time = PlayerPrefs.GetString("EventDuration", "5:00").Split(':');
you should be golden.
Remember, chars are single quotes and strings are double quotes.
Your answer
Follow this Question
Related Questions
How to convert a string to int array in Unity C# 1 Answer
String split script 1 Answer
convert string to list of lists 1 Answer
Change part of a string [Solved] 3 Answers
Strings, Arrays and Split in js 1 Answer