Access script with different names

For the equipment of my project, I need the basic script to access the equipment effect script.

Now, the basic equipment script is always the same, while the effect script has everytime another name (PantsEffect, HelmetEffect, BandageEffect).

How can I tell my basicscript to get the effect script without calling a specific name?

I thought I could do something with scripts filtered by an public variable like:

// To find the EffectScript
    for (this.gameObject.GetComponent(typeof(Javascript))){
        if (this.gameObject.GetComponent(typeof(Javascript)).ThisObjectIsUsable == true){
            EffectScript = this.gameObject.GetComponent(typeof(Javascript));
        }
    }

But it wont work…

Make a base class called for example Effect, then make the PantsEffect, etc inherit from Effect. I don’t know javascript so maybe someone will translate this:

public abstract class Effect : MonoBehaviour {
    //code here
    public void JustAMethod() {
        //do whatever
    }
}

public class PantsEffect : Effect {
    //code here
}

Now you can hold any kind of ~effect class that inherits from effect as

public class JustSomeClass : MonoBehaviour {
    public Effect anEffect; //this can hold any inheriting class reference

}

Even better: if you mark JustAMethod in the base class as virtual, you can override it in the subclasses to do different things. public virtual void JustAMethod() in the base class and public override void JustAMethod() in the subclasses (you don’t have to override though, in that case the base class method will execute).
So if you kept a reference to a script as Effect, you can call the method effect.JustAMethod() and it will execute the override method (if it exists), otherwise will execute the virtual one.

Notes:

virtual and override methods must be public or protected

abstract means you can’t create an instance of the class, ie: its purpose is to be inherited from

you can still execute the virtual method if you have overridden it if you put this: base.JustAMethod() in the override method.

there’s a lot more to inheritance but i can’t cover all of it in an answer, you can find info here: Unity Connect

Here’s an example, say you have a script name “Effects”, with a variable named “myVar” that equals “2.9”.

#pragma strict

private var effects : Effects;

function Start(){
    effects = GetComponent.<Effects>(); //This will get the script, so we may access it.
    print(effects.myVar == 2.9; //this will return true as long as it equals 2.9.
}