

I can also only recommend you to look into the Gamedev tutorial series by Sebastian Lague on youtube.
.jpg)
These things right now most likely dont tell you a lot, but after you've looked into object oriented programming a bit more, you will probably realise what i meant. Or each enemy could have its own instance of it. Since KeywordOptions is mostly a helper class, i would probably have made it static, or a singleton. On top of that, objects do not have to derive from Monobehaviour and do not have to be added as components to a GameObject. As you mentioned yourself tho, you should probably look into objects and instances a bit more. You (accidentally?) prevented this by copying the actual strings that were in the list. Had you assigned the reference, the first enemy too would have had 10 keywords as soon as the second one called ChoseKeywordSet() in your implementation, since it would refer to the then updated list. It technically always was, even tho in your implementation it actually had somewhat of a use. ChoseKeywordSet ( ) Īs you see, the foreach loop also becomes unnecessary. If anyone can point me in the right direction I'd much appreciate it.ĮnemyKeywords = keywordOptions.
#Vvvvvv 333333 code#
Why is that? Doesn't each enemy have its own instance of a keywords class? I have other code based on a youtube tutorial for dialogue, the only difference for which is that it uses string rather than List and doesn't select words from within an array, rather it just selects a random array and that does not have this problem.Įvidently I think this is something to do with using chosenKeywords.Add(), but the reason I'm having such trouble is that I don't really understand instancing or classes very well it seems.
#Vvvvvv 333333 plus#
The second enemy to spawn has the same 5 keywords, plus another randomly selected 5 from another randomly selected set, essentially as if it is building upon the original list of 5 each time it runs the script. What results from running this and having 2 enemies spawned is this: the first enemy to spawn has a keywords class attached to him populated with exactly what I want: 5 randomly selected keywords from 1 randomly selected set. name + "is ready!" ) įor brevity, I removed all of the unrelated code from the enemy script here.
#Vvvvvv 333333 free#
It would correctly form the name, but the GetType and so on would yield a smaller list with items from the wrong list.įeel free to ask me for any better explanation you need, here is how the lists are currently being stored.ĭebug. So far I've tried naming all the List objects that store the keywords under the same scheme, "keywordlist1", "keywordlist2" etc, and then having a string that stores "keywordlist" + a Random.Range operation, and then using GetType().GetField().GetValue() to find the list with that name, but that broke in a very odd way. a list of medical keywords but larger than this) and then, upon calling a routine I want one of the lists to be chosen at random, then a random handful of the keywords from that list to be chosen also.

I want several keyword lists, grouped by theme (E.G. I'm working on a project with a heavy element of randomisation to a certain extent, dialogue will be random, as will another similar feature I currently refer to as "keywords". In other words, I'm almost certain there is an INCREDIBLY simple answer to this problem and the pulling-hair level of anger it's been inducing in me is not worth it. My lack of knowledge does mean however that I randomly encounter roadblocks such as this that are likely incredibly simply solved with just a small amount of understanding I don't have.

Hi, I'm really really new to C# and unity and to be honest I'm just diving right in and trying to learn as practically as possible.
