Another short one. Let's just jump right into it.
Last time, I had questioned whether I could easily write a script that would allow me to randomly generate one of the shape objects I had made. Ths issue was whether I needed to give each object their own script to be able to reference another script that would hold all the logic, or just have that one script that would control everything.
From my, admittedly limited, time researching, it seems like I can work with just the one script. The two main concepts that I'll use are loading resources and instantiating prefabs at runtime. The code for each is short.
The above documentation shows me info for what's called Resource Folders. This will allow me to reference my assets in the scene without having each shape loaded already. So instead of having all my objects loaded onto the scene/level and hiding them for later use, I can just load them when the game requests it. In this case I would reference my assets at the start of the level, and after the user successfully completes the puzzle to get the next shape.
The next piece of the puzzle is how to actually load the objects onto the scene. Again, another short bit of code.
Instantiate(). That's it! Obviously I need to pass some other bits of information, like what object to load, but it's still a very simple piece of code. The great bit about coding is having these pre-built methods and functions that just already do what you need it to do.
So basically what I need to do is look in my resources folders using the code which references the Resources folder for my shape objects. Then randomly determine to load one of them using the Instantiate() function.
My next post will have me actually making the script. This should be easy. But knowing my luck there will be some hiccups. There's always hiccups...
Well, until next time!