ie., if you name one Monobehavior Alice and the other Bob, and they are on the same GameObject, you will end up with two Monobehaviors with the name Bob.
I’m confused by your question. If (script != this) then script isn’t this monobehaviour instance. If (script == this) then script is this monobehaviour instance.
MonoBehaviour[] scripts = gameObject.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour script in scripts)
{
if (script == this)
{
//I find myself in the collection
}
else
{
//Some other script
}
}
If you have a specific class which inherits from MonoBehaviour and you want to turn off every script except itself and this other class, then I might do something like this.
void MyFunc(Component c)
{
if (c is Button) do something;
else if (c is Image) do something;
}
Note that checking whether a variable is equal to “this” is different–that’s performing a comparison on the instance, not the type. If you had 2 copies of the same script attached to an object, only one of them would compare as equal to “this”.