OnGUI needs to exist in the actual script so the engine can call it every frame.
var onGUICode : String;
function Start () {
onGUICode = 'GUI.Box(Rect(310,20,300,50), "Test 123")';
}
function OnGUI () {
eval (onGUICode);
}
By the way, your code wouldn’t actually compile the way you have it; a string must be on one line and quotes must be handled correctly. Also there’s no need to use ToString on a string.
Yes, i know, i made a 10X more complicated script, i just wanted to simplify what it does. the thing is, I dont want to have a code like this:
var startcode:String;
var updatecode:String;
var awakecode:String;
var onguicode:String;
//etc...
function Start () {
//assign the codes to the variables
.....
eval(startcode);
}
function Update () { eval (updatecode); )
function Awake () { eval (awakecode); )
function OnGUI () { eval (onguicode); )
//etc...
And either way, technically, i wont make the code that is being evaluated, so i dont know what functions they will use. Or if they will create new functions. On another topic, I cant seem to be able to make a static variable! it says “unexpected static” or something of that matter. Please help me, this is very important. Thanks.
Eval has some limitations; you can’t just use a string as a substitute for a script. Actually I think it’s kind of impressive that it works as well as it does even with the limitations.