Split string from PlayePrefs


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)

But I get an error: The best overloaded method match for `string.Split(params char)’ has some invalid arguments

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.