Please advice: what's the best way of saving sprites for random sprites prefabs?
Sorry for the abstract question. Here's my setting:
I'm making a puzzle game like Tetris.
I have an empty GameObject called "Game" with a Script component, which manages the pieces creation (instantiating a prefab object) and checks for solutions and does any other game stuff (increasing score, shake the screen, pause the game, etc).
The pieces are a prefab with a script attached. This script manages the piece movement, speed and other things. The prefab has one sprite (actually 5, but I only have a doubt with the main sprite, the rest are effects). Let's say it's initially empty. This sprite can be one of a total of 19 different sprites, and I choose it randomly while playing.
Now, here's what I currently do:
In my "Game" object script, I have a public Sprite array with all the sprites (let's call it "spritesArray"). When the game starts or a piece touches ground, I instantiate a new "piece" prefab, then call the prefab script's "initFalling" function.
In the prefab script's "initFalling" function, I call Random.range to pick a number between 1 and 19, which would be the index of the "Game" script component's Sprite array. I set the piece prefab sprite from the "Game" script Sprites array. I did this thinking that it's better for performance.
Here's my doubt: I'm thinking that it would make more sense (organization-wise) if the Sprites array was in the piece's script component, but as there can be up to 8x12 pieces (prefabs with script component) on screen simultaneously, I wonder if all of them having that Sprite array would affect performance.
Could someone please advice if this change would have no impact on performance?
Thanks a lot in advance :)