# Run a script with a string

**URL:** https://discussions.unity.com/t/run-a-script-with-a-string/19158
**Category:** Questions & Answers
**Created:** [April 17, 2011, 11:25pm UTC](https://discussions.unity.com/t/run-a-script-with-a-string/19158 "2011-04-17T23:25:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![anon39452474](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39452474](https://discussions.unity.com/u/anon39452474)
#### Post date: [April 17, 2011, 11:25pm UTC](https://discussions.unity.com/t/run-a-script-with-a-string/19158/1 "2011-04-17T23:25:23Z")

</div>

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.

```auto
public string scriptName;

void OnUse(){

run scriptName;
}

```

---

<div class="post-metadata">

### Author: ![Statement](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/statement/32/89859_2.png) [@Statement](https://discussions.unity.com/u/Statement)
#### Post date: [April 17, 2011, 11:39pm UTC](https://discussions.unity.com/t/run-a-script-with-a-string/19158/2 "2011-04-17T23:39:38Z")

</div>

Have you looked into [Component.SendMessage](http://unity3d.com/support/documentation/ScriptReference/Component.SendMessage.html) / [GameObject.SendMessage](http://unity3d.com/support/documentation/ScriptReference/GameObject.SendMessage.html)?

```auto
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.
