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:
- drag , drop scripts array via editor.
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.
Comments
Post a Comment