- Home /
Question (or recommendation) on my data structure for getting Prefabs into an array (as gameobjects?)
thanks in advance.... synopsis: Little rpg card game / dungeon crawl with random encounters Currently, this is how my setup loads: I load all my prefab cards (EVERY encounter card I have) into an Object[] and pick one at random to instantiate. Everything's hunky dory with that and 100% random. Now my issue is, I'd like to go back and put some weight to what's instantiate on the board (if it's the first level, put low level/the 'common' cards out there the majority of the time) but my rarity for the cards is listed in a script attached to each prefab. Since these are "objects" and not GameObjects, I don't see any way of calling these scripts and semi-stuck with 100% randomness with the current setup. My code is as simple as var prefabArray : Object[]; Start(){ prefabArray = Resources.LoadAll("Prefabs") } // plus some code to pick one at random and place it on the board My question(s) is 1) is there actually a way to get the scripts on an 'object' somehow? that would be excellent and easiest solution 2) if not - is there an easy way to cast them to GameObjects from an Object array? (if i could do some sort of cycling through all the prefabs and check the rarity, that would be fantastic - sounds like I can only do this with gameobjects though? I'm not even sure that's true since nothing is Instantiated at this point) Otherwise, the only solution I can think of is to restructure my folder structure (instead of just having an "enemy" folder, put a folder for each rarity) (current) Prefabs -- Cards -- ( 6 folders for various card types) DONE. to something like -- Prefabs -- Cards -- Enemies -- EnemiesCommon -- EnemiesUncommon -- rare, legenary, super duper awesome sauce, so on, so on. Then repeat for the other card types. Basically tons of folders that I could do a Resource.load for specific folders (so I count.... 8 card types, 6 rarities for each, then an array for each combination..... carry the 1.... Answer: A shit load. Final answer... no lifeline) Sounds like a pain in the ass, would love a simple solution.
Your answer
Follow this Question
Related Questions
Creating an array of prefabs? 4 Answers
What is the best way to convert a string list to a class list? 1 Answer
Particle Swarm Optimization 0 Answers
Instantiate Prefab Array with ID 2 Answers