Checking if another script exists or not

Hello, I’m trying to figure out how to recognize if a file exists in the assets or not, particularly another script. I’ve gotten a little segment going that will recognize if it’s been attached to a gameobject along with the current script, but it gives a null reference error when the file isn’t present in the assets (removed from the project). Can anyone give me some direction on how to accomplish recognizing this?

Code to recognize an attached object using a custom inspector file:

public override void OnInspectorGUI () {
		serializedObject.Update();

		mainScript Script = (mainScript)target;

		if (Script.gameObject.GetComponents<otherScript>()){
			GUIContent labeltest = new GUIContent("Script Detected");
			EditorGUILayout.LabelField (labeltest);
		} else {
			GUIContent labeltest = new GUIContent("Script Not Detected");
			EditorGUILayout.LabelField (labeltest);
		}
	}

I found a solution. It’s not as elegant as I’d like, as it requires the file be in a specific location, anyone know a way to expand this to recognize it in any location under Assets?

Solution so far:

public override void OnInspectorGUI () {
		serializedObject.Update();

		mainScript Script = (mainScript)target;

		if(File.Exists("Assets/Scripts/otherScript.cs")){
			GUIContent labeltest1 = new GUIContent("Script File Detected");
			EditorGUILayout.LabelField (labeltest1);
			if (Script.gameObject.GetComponent("otherScript")){
				GUIContent labeltest = new GUIContent("Script Attached");
				EditorGUILayout.LabelField (labeltest);
			} else {
				GUIContent labeltest = new GUIContent("Script Not Attached");
				EditorGUILayout.LabelField (labeltest);
			}
		} else {
			GUIContent labeltest1 = new GUIContent("Script File Not Detected");
			EditorGUILayout.LabelField (labeltest1);
		}

Anyone seeing this post in the future, please note File.Exists requires System.IO inclusion.

Reflection. A good starting point could be http://msdn.microsoft.com/en-us/library/system.reflection.assembly.gettypes(v=vs.110).aspx

Exactly what I was looking for, thank you so much!