Running script/lines of code

At the moment I’m in the process of making a dialog system, but I’m a bit confused, before throwing up our dialog box with its text, say we want to move our npc before they say the next piece of dialog, what would be the best route to take for this?

I had the idea of making a new script called DialogFunctions which just contains a list of functions, then in the inspector you type in the function name, in which case it takes the variable in the case of a string and sendmessage the function.

public string functionToExecute; // this gets filled in in the inspector

void OnGUI () {
    if (functionToExecute != "") {
        gameObject.sendmessage(functionToExecute);
    }
    // continue with showing dialog
}

I’m not sure I understand the question. I’ll answer the best I can – it’s my first time. Is this a part of a separate object that contains the OnGUI call.

Finding the right targetobject per function is another ball of wax that depends on your application. You could just make another public variable, tag the object(and use findByTag), name it a specific way, or some other way of singling out the object you want. ( http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html )

I’ll assume that this is some Dialog subclass that gets created or activated when the dialog should be shown. If that is the case, then you just but the sendmessage call in the awake() or start() function.

If you are using some other system, then just use a boolean flag to indicate that you should in fact run that code once ie:

where otherDialogPrerequisite is whatever would cause your dialog to be shown and targetObject is the one you want to select.

bool hasRunBefore;

function OnGUI()
{
if(otherDialogPrerequisite == true && hasRunBefore == false){
hasRunBefore = true;
targetObject.sendmessage(functionToExecute);
}
}