[Editor Script] AddComponent Multiple Objects

I have an editor script with a button that adds a Script to the gameObject. If multiple objects are selected, the script is added to the first one only. Here’s my script

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor ( typeof(SomeScript) ),CanEditMultipleObjects]
public class SomeScriptEditor : Editor {

	public override void OnInspectorGUI(){
		
		EditorGUILayout.LabelField( "Node adder" );
		if( GUILayout.Button("Add Node") ) {
			SomeScript go = target as SomeScript;
			
			Node node = go.GetComponent<Node>();
			
			if( node == null ) {
				go.gameObject.AddComponent("Node");
			}
		}
	
	}
}

Am I doing it the wrong way? Shouldn’t the editor script run for every separate object?

Jenci1990 has put you on the right track, I will expand.

First you need to tell the script what object it is looking at with target:

private SomeScript myScript;

 public override void OnInspectorGUI(){
myScript = (SomeScript)target;
}

When adding an object (basing this part off what i THINK youre after):

 if( GUILayout.Button("Add Node") ) {
myScript.transform.gameObject.AddComponent("Node");
}

if you want to make sure that a node does not already exist before adding it, simply turn off the button if node = true;

private bool nodeExists;

SomeScript check = myScript.transform.GetComponent<SomeScript>():

if(check){
nodeExists  = true;
}else{
nodeExists  = false;
}

if(!nodeExists){
  if( GUILayout.Button("Add Node") ) {
 myScript.transform.gameObject.AddComponent("Node");
 }
}

The above will not display the button to add a node in the inspector if the node already exists with a simple bool

Uhm, since the ability exists to edit multiple objects at once the Editor class got extended with targets. Sometimes it helps to just browse through the documentaion and looking for something that might be useful ^^

if( GUILayout.Button("Add Node") )
{
    foreach(var obj in targets)
    {
        SomeScript go = obj as SomeScript;
        if (go == null)
            continue;
        Node node = go.GetComponent<Node>();
        if( node == null )
        {
            go.gameObject.AddComponent("Node");
        }
    }
}