Put a prefab in a gameObject slot through code

I want to do a store in my game, and i need to change the bullet type each time i buy an item, so, how can i add a prefab of a bullet, wich i already have, into that Ninja Star gameobject slot, using code?

87870-unity.png

You can do that with Resources.Load("Prefabs/Bullet") as GameObject;, which means your Prefab musst be at “Assets/Resources/Prefabs/Bullet”, or another location in the resource folder. See Resources.Load.

But I would rather load all of them and then select in code which one to use.

You can make an array of all prefabs, and when someone buys something, assign the NinjaStar var to be the prefab you want from the array.