|
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?
(comments are locked)
|
|
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: Fantastic answer!
Aug 03 '11 at 11:28 AM
save
o hai
Aug 03 '11 at 11:29 AM
biohazard
I had a break from work for few days and now when I wanted to implement this I found out that the check if the building can be built indoors has to be done BEFORE the instantiation.
Aug 04 '11 at 08:53 PM
4illeen
(comments are locked)
|

Do the instantiated buildings have scripts attached to them in the first place?
at the moment no, the player has everything on him right now
In that case, I would make a script and attach it to the prefab (the buildings are prefabs, right?). How many different kinds of buildings are there?