Run a script with a string

Im current working on a rpg game and i want the player to press buttens etc. Now i have when the player press a button it run a function on the button.

But i want so the function on the button runs a script that i can change on diffrent buttons etc, something like this.

public string scriptName;

void OnUse(){

run scriptName;
}

1 Answer

1

Have you looked into Component.SendMessage / GameObject.SendMessage?

public string scriptName;

void OnUse() 
{
    SendMessage(scriptName);
}

It will call a method called whatever scriptName is set to, on all components of the current game object.

Thanks for this :)

–

thx that really helpt

–