Hi all,
I’m relatively new to Unity3D, and I’m trying to find out some things about its scripting abilities. We have an interactive educational app using a different 3d engine, and we think that it’s time to port it to Unity. However, our app has a sort of strange feature: It allows the user to write an arbitrary script, and then execute it, so as to observe its results in the 3d scene. For example, a user could write a script that would allow getting the first object of the scene, rotating it for, let’s say 20 degrees around the y axis, and then moving it 5 units forward. The user would then compile the script and execute it, causing the object on the scene to rotate and move accordingly.
Can this be done in Unity? Can scripts be written and executed on a running scene, real-time?
Thanks in advance
Th.Mantes, Greece
I assume you have your own mini-scripting language for this, and that the users write and execute the scripts in-game?
If so, then I imagine you’d just implement the same system in Unity much as you did in your original framework. In other words, it wouldn’t be integrated into the Unity engine in some sort of special way, but would just be implemented and executed like any other code.
To maybe help clarify things a bit, what’s often referred to as ‘scripting’ in Unity is really just programming; in other words, it’s how you program your game. It sounds like what you’re talking about is more of a game-specific mini-scripting environment, which would just be something you’d program like anything else. As far as that goes though, yes, of course it could be done.
(Maybe there are other options though that I’m not considering; if so, I’m sure someone will point them out.)
eval could do that but as you don’t want low level access just higher level onto designated objects as it seems, you might actually want to add an own scripting layer as eval will allow them to access anything in the project
You could possibly also get very fancy and package the Mono compiler in with the finished app.
If you can manage compiling the assembly, then you can load it at Runtime and access it through reflection.
This would allow you full access to the API(provided you properly manage the linking), however it is definitely not a trivial solution, and would be a difficult feature to implement.
Note: I’ve not actually done this, so this is more of a Should be possible than a guarantee it is.