- Home /
Wich way is better?
I have a game with 9 granate types with different scripts, models and materials but the same functionality. I don't know if it's better to put them in to 9 different prefabs or to create 1 prefab and put a script on it what say what kind of granate that is and attach the right script material and so on on it. Ich way is more accurate and more efficient ?
Answer by Pharaoh_ · Apr 26, 2016 at 09:08 PM
Definitely the second. It actually follows the principle of coding new types through inheritance. If you want to create more types of this prefab, you simply create a material and attach the proper mesh (for this I'd go with a Dictionary by the way). Plus, faster building time!
Ok so i create 1 prefab and put a script on it who know what granite type it is and than the script attach the right material mesh and granite function script ?
Yeah! So, create your prefab somewhere and attach a script on it. At the Start() method of this script, you can call a method that takes a string as a parameter. Then, load from your resources folder the material and the mesh with the same string as a name, access the renderer component and apply the new mesh/material.
Ideally, you should use Object Pooling to prevent loading from the Resources folder all the time.