Referencing a Script through a Public String with GetComponent

In this game I’m working in I want to make a reusable script that contains a reference to the PlayerFollow script. But depending on the nature of the level, I use different PlayerFollow scripts. Because of this, I have to write a different script for each Player Follow script. To get around this I tried using a public String for entering the Type of the Script Component I’m referencing from the editor. But it does not work as intended.
Is there a better way? Thanks!
My code:
.

public string ScriptType;

//I would add the Type of the script through the editor

private void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player"))
    {
        other.GetComponent<ScriptType>().enabled = false;

       
    }
     
}

Using Interfaces in Unity3D:

https://discussions.unity.com/t/797745/2

https://discussions.unity.com/t/807699/2

Check Youtube for other tutorials about interfaces and working in Unity3D. It’s a pretty powerful combination.

1 Like

Interfaces seem really useful. Thanks

1 Like