Convert String To Class

I have a String CharName and i want:

CharName CharStats = (CharStats)Player.tranform.Find("Mesh").GameObject.GetComponent("PlayerController") as CharStats;

The problem is I can’t Declare CharName CharStats since CharName is a string. But CharName contains the name of a class (script). Let’s say the script is named TestScript the line should become:

TestScript CharStats = (TestScript)Player.transform.Find ("Mesh").GameObject.GetComponent("PlayerController") as TestScript;

So my question how to convert the String CharName to be used as the class TestScript.

Thank You :slight_smile:

I am currently using the switch case method but if I will continue the code will become VERY long so I’m sure there is a better way to do this without making a switch case with 100 cases.

Solved It !
To Call The Value Use This (In Case Someone Else Wants Help):

(float)CharStats.GetField ("VariableName").GetValue(typeof(float));