I tried to search for this question, but I don’t know what terms I can use without just finding forum posts comparing C# to JScript to Boo :I. I was wondering if there is a simple way with Unity to provide a scripting language (ideally C#) for players to use to add their own behavior to my game? Obviously, these player scipts would work with the release build of my game, where everything is already compiled. Specifically, I have a highly-customizable random level generation system and I was wondering if I could let players create their own small classes to add new functionality to my system. I never tried providing scripting languages to players in a game before; their scripts would have to compile to a C# class, inheriting from a specific abstract class that my generation system holds a collection of.
It depends on the platform… IIRC OSX, Webplayer and windows yes, the others no.
The command is eval() IDK IIRC you just plunk a string with script in there and it works but I also think that it would be dangerous as it gives users full control, i’m not sure though as I’ve never used it.
Thanks for the quick reply! Yeah, I was thinking of introducing some way of parsing and searching for any classes that are not in a pre-approved list. So how exactly do I access the eval() function?
You can use eval() with Unityscript to execute arbitrary code at runtime, but it has some limitations (such as not working on iOS). Also, executing arbitrary code strings has obvious security issues.
–Eric
I honestly have no idea, but I guess you just put a string inside so the like of code is just:
eval(String);
Does it work on Android?
What I meant was, “What class possesses the eval() method?” My guess would be MonoBehavior (or whatever the Unityscript equivalent is called)
Good question.
MonoBehaviour is a Unity class, nothing to do with any specific language. Anyway eval is a language feature and not part of any particular class.
–Eric