- Home /
Attaching default script to prefab
So I'm creating a 3D puzzle game using 3ds max and importing the .max files directly into unity. My problem is lots of my levels have world hazards, such as spikes or what not and I need to attach a kill script to all of these.
The script pretty much just turns whatever object it's attached to, to be a trigger (so I don't have to manually change them all, but a secondary question is how could I set them to trigger by default without a script) and just have an event whenever the player touches the object it sends a message to the player to die.
Now this wasn't much of a problem originally but my most recent level has over 450 spikes, in groups of around 15 so I can't just easily highlight them all in the editor (I don't want the circular platform they attached to, to have the script). I don't mind setting a kill script to them all once, but it breaks the prefab and makes updating hard.
So is there anyway that I can have scripts attached to all these spikes by default without breaking the link to the prefab either in max or unity?
Thanks
Answer by Jessy · Jan 21, 2011 at 01:18 AM
There's no way to maintain a link to the hierarchy of an FBX file after you add a script. However, the mesh that your Mesh Filters links to is preserved, which should be all that you need to worry about.
Unless you do a manual Reimport, then it resets everything sometimes.
Thanks for the reply. I ended up solving my problem by writing a script to attach the script to all child objects. Easier than manually attaching it to 400+ objects.