Hey, i want to modify my unity editor, so i write a script to add components with their name. You can write the name in a textfield an then it adds the component with the name to den game object. But then i would add a component to the childrens, but this doesn't work. error : No appropriate version of 'UnityEngine.Component.GetComponentInChildren' for the argument list '(String)' was found.
here is my script code:
enter code here
function OnGUI() {
newcomponent = EditorGUI.TextField(Rect(10,25,position.width - 20, 20),
"Component:",
newcomponent);
if(Selection.activeTransform)
if(GUI.Button(Rect(0, 50, position.width, 30), "Add Component"))
for(var t : Transform in Selection.transforms)
t.gameObject.AddComponent(newcomponent);
if(GUI.Button(Rect(0, 85, position.width, 30), "Remove Component"))
for(var t : Transform in Selection.transforms)
if(t.GetComponent(newcomponent) != null){
DestroyImmediate(t.GetComponent(newcomponent));
}
else{
if(t.GetComponentInChildren(newcomponent) != null){
DestroyImmediate(t.GetComponentInChildren(newcomponent));
}
}
if(GUI.Button(Rect(0, 120, position.width, 30), "Deactivate"))
for(var t : Transform in Selection.transforms)
if(t.GetComponent(newcomponent) != null){
t.GetComponent(newcomponent).enabled=false;
}
else{
if(t.GetComponentInChildren(newcomponent) != null){
t.GetComponentInChildren(newcomponent).enabled=false;
}
}
if(GUI.Button(Rect(0, 155, position.width, 30), "Activate"))
for(var t : Transform in Selection.transforms)
if(t.GetComponent(newcomponent) != null){
t.GetComponent(newcomponent).enabled=true;
}
else{
if(t.GetComponentInChildren(newcomponent) != null){
t.GetComponentInChildren(newcomponent).enabled=true;
}
}
`enter code here`
I think i need a function like parsetype or something. Does anyone have a solution for this problem?