Hi there,
i created this Script to ask for a specific Script inside a GameObject. if it doesn´t exist, a Button should appear to create the Script in the GO.
The GetComponent works, the button works - but the AddComponent not…
This is the Script:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class Sys_EventList : EditorWindow
{
GUISkin new_skin;
Vector2 scrollPos;
Sys_EventRun eventscript;
// Add menu item named "My Window" to the Window menu
[MenuItem("RPG System/Event List")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(Sys_EventList), false, "EventList");
}
void OnGUI()
{
new_skin = Resources.Load("GUISkin_Event_System") as GUISkin;
GUILayout.Label("Event Liste", EditorStyles.boldLabel);
EditorGUILayout.HelpBox("Click on a Event Command to open its settings or delete it.", MessageType.Info, true);
eventscript = null;
if(Selection.activeGameObject != null){eventscript = Selection.activeGameObject.GetComponent<Sys_EventRun>();}
if(eventscript == null){
EditorGUILayout.HelpBox("Add the Sys_EventRun Script to your GameObject to activate the Event System for it!", MessageType.Warning, true);
if(GUILayout.Button("ADD Sys_EventRun to Object")){
Selection.activeGameObject.AddComponent<Sys_EventRun>();
}
}
}
}
The only thing that happens is, that an empty Component named “Script” is attached to the GO…
Instead of my Script ._.
What is wrong here?