Is there a way to load an arbitrary script at runtime and attach it to an object? The script source would, for example, be read from a file at runtime, or even entered through a GUI.
Thanks!
Is there a way to load an arbitrary script at runtime and attach it to an object? The script source would, for example, be read from a file at runtime, or even entered through a GUI.
Thanks!
'fraid not. All of the scripts are compiled to bytecode before the game is run in the editor, and when the game is built, so there is no way to dynamically load script files into the system. Mono isn’t an interpretive scripting system.
You can, however, write your own script system if you can handle the headache and the overhead, but I don’t recommend it.
Perhaps use data files for a happy medium.
-Jeremy
Javascript does have eval() now in Unity 2.0, which can run arbitrary strings as code during run-time. I haven’t played with it much, but I wasn’t able to get it to work outside the editor (works fine in the editor), which doesn’t surprise me. But then I might have been doing something wrong.
–Eric
If all you want is very very basic commands, it’s not too hard to just parse a file yourself.
You can even use XML if your commands can be defined in such a structure.
-Jeremy
Cool, thanks for the infos.