- Home /
Unity Editor Custom script
Alright, I wanna make my custom script in the Editor, but I'm not sure how to finish it, Check out the script there's 1 thing that isnt working properly, and the other i dont know how to do.
The thing that doesnt work im guessing it must be an unity bug, the shortcut doesn't work (im on windows) if i do crtl+c but it works if i do the same with my capslock on, (even thou its a small letter), so if someone can explain why this is... also, the other thing i dont know, is how to select the item i have just created in the Hirearchy, thanks.
using UnityEditor;
using UnityEngine;
class ResetObject : MonoBehaviour {
// Add menu named "Do Something" to the main menu // and give it a shortcut (ctrl-o on Windows, cmd-o on OS X). [MenuItem("kici/New GameObject %c")] static void NewObject() { new GameObject("kici");
// Debug.Log("Perform operation");
}
}
Answer by chief1234 · Mar 11, 2011 at 01:19 AM
Your shortcut issue looks like a bug to me.
To select your new object you just need:
static void NewObject() {
GameObject newObject = new GameObject("kici");
Selection.activeGameObject = newObject;
// use this to highlight the object in the hierarchy
EditorGUIUtility.PingObject(newObject);
}
how does the shortcut look like a bug ? whats the propery way, i even tried only wiht "k" and "$$anonymous$$" they both work (only if caps lock is on..?
I meant a bug with unity. Have you tried out any of the other shortcut options? I'm sure you've seen this page: http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$enuItem.html I can't see why yours isn't working.
yes i have... well that sux i dont have time to report another bug again, since they didnt even reply to my last one :S (RPC's didnt sent to the client LOL);;; thx i'll give u the answer!
This is the error i get:
Error 1 Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.Object[]'
on this line: Selection.objects = newObject;
Well, I usually use unityscript, so I'm not sure how to resolve that error - so I changed the code a bit ins$$anonymous$$d. Assigning the new gameObject to Selection.activeGameObject works just fine since you're only assigning one object anyway.
Answer by Zogg · Dec 17, 2011 at 11:30 PM
If %c doesn't work, maybe you should try another shortcut. For me, some shortcuts work (%m, %g...), some don't (%c, %f...).
Looks definitely like a bug to me. Or maybe the ones that don't work are "reserved" by Unity for whatever purpose - but if this is the case this should be documented somewhere, I think.