Search Unity

assign scripts to instantiated prefab through script

Discussion in 'Scripting' started by Krodil, May 11, 2013.

  1. Krodil

    Krodil

    Joined:
    Jun 30, 2010
    Posts:
    141
    hey,

    basically. I have a range (50+) prefabs of objects with many scripts on.
    These objects are instantiated through a menu, but it is getting quite tedious to add/remove all these scripts for all objects when I change something or make a new script.

    Is it possible to add ONE script which at instatiation will add all the other scripts I need on these objects?
    I tried AddComponent() in the instantiate function..no luck
    and to assign through a Start func....no luck there either.
    best,
     
  2. rapidfirestudio

    rapidfirestudio

    Joined:
    Jan 31, 2013
    Posts:
    73
    Take a look at:

    http://docs.unity3d.com/Documentation/ScriptReference/GameObject.AddComponent.html

    And:

    http://docs.unity3d.com/Documentation/ScriptReference/RequireComponent.html

    If it's not working you're not doing it correctly, AddComponent does exactly what it should. Try posting your code here if you want more specific help.
     
unityunity