External script access

Hi guys,

How i can access other scripts with a string var in c#;

I have a lot of enemies and each enemie have a different script, but all of them have the same function to have damage.

if(hit.gameObject.name=="zombie"){
     hit.getComponent<AIscriptZombie>().hit(var1, var2, var3,etc);
}
if(hit.gameObject.name=="vampire"){
     hit.getComponent<AIscriptVampire>().hit(var1, var2, var3,etc);
}
if(hit.gameObject.name=="archer"){
     hit.getComponent<AIscriptArcher>().hit(var1, var2, var3,etc);
}

How i can make this simply like this:

string scriptname = “AIscript”+ hit.gameObject.name;

hit.getComponent().hit(var1, var2, var3,etc);

I learned unity alone and there are little tricks that I don’t know xD.

Please one help :smiley:

Thanks…

Use the version of GetComponent that takes a string argument, see second example at Unity - Scripting API: GameObject.GetComponent.