Applying a Prefab to a Variable

Hi all, this is most probably an easy fix, but I have been looking for it for quite a while.

How do I assign a prefab to a variable without running it through the inspector?

For example I want to create a system that is like the following

   var Weapon;
switch(Weapon){
case ("Large Stick"): Weapon = prefab("Large Stick"); break;
case ("Candycane"): Weapon = prefab("Candycane"); break;
case ("Lazer"): Weapon = prefab("Lazer"); break;  
}

This is sorta the idea I’m looking for and i know the above script wont work, I am just asking how it is done.

Thanks Myhijim

Well, you’ll have to reference your objects somewhere - whether you type the 100 names in your script, or just drag the 100 prefabs into an array, it’s not much of a difference, and the latter will give you much less hassle when dealing with your objects (although it will be more problematic if you later need to insert/delete objects from that array. Appending at the end is no problem)

One other method would be to put all your prefabs into a folder named “Resources”. Then you can use Resources.Load(“name”) et al. to refer to these objects and instantiate them. However, note that the “Resources” folder will be included in all your builds, so the larger it gets, the larger your application will become, and unused objects in there will waste file size space of your application.