Can I prevent a certain script from being attached to a certain game object?
Hmm that is a nice question!
Let us say we want do not want to allow user to attach component CompA to a GameObject if CompB is already attached. Try this :
private void Awake()
{
if (this.getComponent<CompB>() != null)
{
Debug.LogError("You can not attach CompA if CompB is attached too");
Destroy(GetComponent<CompA>());
}
}