In my game player is able to instantiate various buildings and objects in front of him (aka build stuff). The thing is I need them to hold some info about their properties (like some objects cannot be instantiated indoors, some need to be built on other objects etc).
I see two ways to solve this problem, one through scripting - which seems a bad idea to me, probably because I'm a unity rookie - is to make a new class BuildingInfo and hold all the bools inside. But as far as I know, I'd have to add this script to each prefab and then use a giant switch while instantiating to check objects name and set those variables.
My second idea was to add empty GOs to the prefabs with descriptive names like ThisCannotBeBuiltIndoors, and simply check for children just like I'd check if the bool was true or false. The real question is - are empty game objects somehow bad for the memory usage/performance/other, if there are few of them on each prefab?
Is there any other easier way around I cannot see?
Having Unity create an empty GO just to use its name to define some sort of behavior is huge overkill and a quite odd way to go about solving this, I think. :) Like save pointed out in the above, you're not making individual scripts for each combination. Instead, you're setting variables in each script instance to represent the characteristics of that particular building.
Here's the general idea, more elaborately explained:
You didn't mention which programming language you're using, so I'm going to take the liberty to choose C# for the example. ;) Hope it's alright, if not, I'm sure you can translate it to whatever you use. Here's what the BuildingScript could look like:
Here is what it would look like when you instantiate buildings:
answered Aug 03 '11 at 09:27 AM