GetComponent(); issue

Hi so I have a script that I want to handle all interactions so when a mouse clicks something it easily knows where to go from there

The idea is that you on click the raycast finds the interaction script and then in the interaction script it will have a variable which is set Per Object as to what script it will activate, Example : If the interaction script is on a spawner the raycast will activate the interaction script and then the interaction script will activate the Spawn script

This script is obviously incomplete and is the bare minimal to show where I am heading with the code

	public bool Active;

public string ScriptName;
public bool RequiresRaycast;

void Update(){
	if (Active == true) {

		UnknownScript = transform.parent.GetComponent<ScriptName>();
		UnknownScript.Active = true;

		Active = false;

Is there a way I can get this to use a string in .GetComponent? It seems quite complicated considering you need to make it a variable itself when you get it so it would mean I would have to make it literal when I write it like “ScriptName = transform.parent.GetComponent();” the first part “ScriptName” would have to be a new variable using the strings variable and not to try and reset it… God knows

Ps: the RequiresRaycast variable will be implemented later for when script clicked needs the information of where it was hit, example : Movement on terrain

If ScriptName is a string, you must use the non-generic version of GetComponent, and treat it as a MonoBehaviour:

MonoBehaviour UnknownScript = transform.parent.GetComponent(ScriptName) as MonoBehaviour;

I also recommend using .enabled rather than defining your own .Active as .enabled will probably do what you want already.