Hi everyone.
Im trying to create something to hold a list of strings that I can access in other scripts. I want to have the strings separated into categories so I thought the best way would be to keep them in different arrays. So one array for one group of strings and another for another.
What would be the best way to do this? Perhaps a scriptable object?
Thanks
Based only on what you said seems like you need a Dictionary<String, List> or something like that.
cant really answer that one for you. Depends on your criteria. i.e. how is it access, speed, complexity of the logic …
Your question is very general. It’s best to ask questions about a specific step.
I’ve give you one example, but most likely it doesn’t work for what you want.
using UnityEngine;
using System.Collections.Generic;
public class StringHolder {
// Singleton
public static StringHolder instance = new StringHolder();
private StringHolder() {
dictionaryOfStringLists = new Dictionary<string, List<string>>();
}
public Dictionary<string, List<string>> dictionaryOfStringLists { get; private set; }
}
You can then access the strings like so
Dictionary<string, List<string>> strings = StringHolder.instance.dictionaryOfStringLists;
strings["First Names"] = new List<string>();
strings["First Names"].Add("Garth");
foreach (string firstName in strings["First Names"]) {
Debug.Log("A first name: " + firstName);
}
Thanks everyone.
What I am trying to achieve is is have a load of different strings that will be used for dialogue. The strings will be split into groups so that they can be accessed in different states e.g. Happy state would have one group of strings and Sad state would have another.
there is only one character in the game so I’d imagine it would only need to be basic but I have never done anything like this before so I just dont know where to start.
Thanks again