|
Heya guys, I'm currently working on a architectural visualization of a huge building. I was painstakingly making every door operable manually until someone pointed me in the direction of prefabs. Now My understanding is limited so bare with me. So I have made a prefab which is operable (open/close) and it works fine. It is the exact same mesh as all the other doors in my level. (It is in fact the same model) in every way except for the attached door script and box collider (inside an empty game object renamed to hinge). I want to swap all my doors (placeholders) for the prefab. this isn't in game just in the building of the model/level. Is this at all possible? swap one "item" for another? any help as always is greatly appreciated. Chris
(comments are locked)
|
|
Hey guys, I'm not getting this to work :( Bare with as I'm just getting to grips with this whole scripting thing. You have the line/s //Swap out prefabs to new ones based on which ones are obsolete if(transforms[i].gameObject.name == "Heart") objectName = "C_Gem"; So I swap out "Heart" with the existing models name and where it says "C_Gem" I put the name of my prefab in right? Then I select the existing models in game and hit CTRL+R and it should swap out all the existing models to the prefab stated in the string? If so, It's not happening for me.
(comments are locked)
|
|
Here's a modified script that I use to replace prefabs in scenes by name. It works base don selection within the editor, so just select all your objects and and hit CMD+R. It will look through your scene and find prefabs that match the names of the objects in your scene. you can modify the code to create substitutions. Put this in your Editor folder (requires Unity Pro) If anyone has any idea how to make this script more flexible please let me know. } Hey man, I appreciate the help but maybe I should have mentioned that I'm using windows :( I'll google the equivalent of "CMD+R" and give it a try. The existing "models" aren't prefabs though. Will that make a difference? Thanks alot.
Apr 04 '12 at 05:28 PM
morphus1
This doesn't require Unity pro. No pro feature has been used in this editor script. CMD+R is the hotkey defined in the MenuItem ( Anyway this script isn't very robust. If there are two prefabs with the same name but in different folders it will instantiate both but only use the last one.
Apr 04 '12 at 05:39 PM
Bunny83
It doesn't matter if the models are prefabs or not, the script just replaces the objects by name. I used it to replace broken prefabs and turn them back into prefabs. Bunny is right that the script is kinda crap but it gets the job done. I didn't run into the problem he's pointed out with the multiple instances but not that he mentions it, it's kind of obvious that would happen :S
Apr 04 '12 at 06:29 PM
kalvinlyle
(comments are locked)
|
