c# - store a reference to a script to attach at runtime -


another best practice question. have list of scriptableobjects (thanks learningcocos2d) defines list of sprites can load @ runtime.

i followed tutorial: http://www.jacobpennock.com/blog/?p=670

in order drive custom behaviour, want different scripts applied various in-game objects when instantiate them. what's best way store references desired scripts want apply?

[edit] more details:

my scriptable object simple list of serializable objects. have series of defined scripts want attach objects define. unity not seem allow me store reference script using below method.

public class testlist : scriptableobject {     public list<motionspritedata> motionsprites; }  [system.serializable] public class motionspritedata {     public component motionpath; } 

create class loads scripts array. class not have monobehaviour, example be.

you have 2 options:

  1. drag , drop scripts array via editor.
  2. or put scripts in resources/scripts/ folder can loaded @ run time.

    public class scriptmanager : monobehaviour  {    public object [] list;     void awake()    {        // comment line if used step 1 above.        list = resources.loadall("scripts");          gameobject.addcomponent(list[0].name);    } } 

now can use own logic determine gameobject gets script, should trivially easy you.

enter image description here


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -