Set Type by String

Hi, I have some problems. I’ve switched the platform target to Android, and a lot of errors came out. I noticed that most of them are of this type:

BCE0019: ‘OnCollisionEnter’ is not a member of ‘UnityEngine.Component’

It is not for the function ‘OnCollisionEnter’, because a lot of other “members” (such as variables) are not recognized. Where i use the name for getting component it is needed, and calling something on that component of type “Component” is impossible. Even specify the type before use it isn’t usefull, because the type specified doesn’t exist (he says).

I’ve a script where the name of the script to access is a variable, so it can be only a string, i really have to create n scripts for n variables?!?

Edit: Sorry, this is the interested part of my code:

var FixedUpdate : boolean = true;
var CollisionEnter = false;
var CollisionInfo;

var script : GameObject;
var scriptName : String;

function OnCollisionEnter (collision : Collision) {
	script.GetComponent(scriptName).OnCollisionEnter(collision); // Error is here.
	CollisionInfo = collision;
	CollisionEnter = true;
	if (FixedUpdate) yield WaitForFixedUpdate();
	if (!FixedUpdate) yield WaitForEndOfFrame();
	CollisionEnter = false;

The main problem is that the script to access is determined by the var scriptName, and I have to cast the type from component to scriptName, because the script type isn’t known before the script start.

In another script I access to “enemy.GetComponent(scriptName).Life” because there are different enemies with different scripts, and I created the script for be used with all of them.

Edit: I still didn’t solve the problem, and my project is totally stopped, can you help me, please?

Edit: So, i tested some stuff for bypass the problem, but the error is always the same: TOT isn’t a member of ‘UnityEngine.Component’.

I used this method:
Instead of using a String for get the script, i declared a var of type MonoScript, the same that is shown as first variable of every script component.
Then, reading from this page (Unity - Scripting API: MonoScript.GetClass), i used this lines:

var type : System.Type = enemy.GetComponent(EnemyInfo).enemyScriptType.GetClass(); //enemyScriptType is of type MonoScript.
enemy.GetComponent(type).Life -= damage * (1-Vector3.Distance(, enemy.transform.position)/BigLaserRange);

I thought that the problem was solved, but again the error was the same. Where I get wrong?

GetComponent(scriptName) returns a Component type and Component does not have a OnCollisionEnter function. You should store and typecast the returned object to your script name or get rigidbody/collider component.

Thanks to renman3000 now i can continue my project. This is the solution suggested from him:

Instead of trying to reach the script, he suggested to use GameObject.SendMessage(), this solution calls a function (with values) in all the components of GameObject, so if a Script has that function, it will be executed.

So this is the example from docs:

// Calls the function ApplyDamage with a value of 5
gameObject.SendMessage ("ApplyDamage", 5.0);

// Every script attached to the game object 
// that has an ApplyDamage function will be called.
function ApplyDamage (damage : float) {
    print (damage);

Again thanks to renman3000 for he’s brilliant solution.