I build a menu inside the OnGUI function like
GUILayout.Label("Singleplayer");
if(GUILayout.Button("Zombie"))
ChangeScene("Zombie");
Is it possible to add a Dropdown programmatically like i create the button?
If you're doing this in the editor - i.e. a custom Inspector or EditorWindow - then yes:
https://docs.unity3d.com/ScriptReference/EditorGUILayout.DropdownButton.html
But if you're doing it in-game, you need to stop using the OnGUI method (it's not supported any more by Unity) and switch to using the new UnityUI (which isn't really "new" any more - it went live almost 5 years ago! :)). UnityUI has built-in drop-down functionality you create directly in the Editor:
https://docs.unity3d.com/2018.4/Documentation/ScriptReference/UI.Dropdown.html
and:
https://docs.unity3d.com/Packages/com.unity.ugui#1.0/manual/script-Dropdown.html
Related
I try to handle some events during animations, but everywhere I look, every tutorial have access to AnimatorEvent Inspector like this:
A nice simple field, where you can select a function, I want this!
But instead of this, I always getting this sick 5 fields view, and don't have any idea how to handle animation event in this case!
I tried to create function test() with debug log, but it didn't work anyway. Why I can't get access to this simple window where I can choose an function?
You will need to add this animation into a State in Animator Controller (via Animator Window).
In the object which contains Animator component, attach your script component to it.
Open the Animation window, select the object above, you will see a dropdown of animations (top left) which Animator Controller of this object contains. Choose and add event to the animation you want to.
Select the event in Animation Window, in the Inspector, you should see the dropdown of public functions of your script component attached above.
Answer by Aluminium18
Sometimes it doesn't work even if you do all things according to tutorials or advices in internet. I often leave Unity editor launched for a long time without any interactions with it. After several gibernations and several days it can get buggy - various errors appear, you can't see some functions from scripts and so on. So, just reloading the Unity editor solves many of such issues for me. And it continues to happen so for several years no matter what Unity version you have. I tried versions from 2019.x.x to 2022.x.x - all this time Unity behaves itself the same.
I'm new to unity. I want to try this tutorial but I failed.
I created a GameObject - UI - Button, and tried to add script to Canvas. But I got this error. Any help would be appreciated.
OpenFolderPanel is an Editor script which lets people to make some customized function for Unity Efitor.
If you want to click button to show file dialog in your game, you can try StandaloneFileBrowser
Alright, I know your mistake. When you create a c# script, do as follows (if you want to attach it to a gameobject).
1) Select the gameobject in the heirarchy.
2) Click add component in the inspector window.
3) Type in the name of your new script, and Unity will generate a basic script derived from MonoBehaviour automatically.
BTW, game objects have monobehaviour derived scripts on them (in singleplayer). The script you are using is derived from EditorWindow, not MonoBehaviour. Personally, I have not used a custom editor, but I think the script you are using should work automatically without having to attach it to a gameobject.
Rocket for Mac has a Preferences Window in which it has a form like below to insert & remove an app.
I want to make a form like that but how should I build it? I am new to Cocoa development so this might be obvious.
I want to make the one with the label Disable Rocket within these apps:
I found a solution.
What I did was use NSTableView with single column for the textbox. And made the NSTextField in it to be text editable using the Behaviour attribute.
Then for the + & - button I used 2 NSPopupButton & made the Image attribute to be NSAddTemplate & NSRemoveTemplate which exists by default in Xcode. There are bunch of other images that are default in it.
That solved it for me :)
The latest versions of NGUI have this great tool that lets you pick which function within any of the target's scripts will be called when you click on it.
Basically, it's a select box within the inspector that gets automatically filled with all the functions from all the scripts attached to the game object.
How can I generate a function list that fills up automatically like this?
I don't want to have to maintain an enum with all the possible functions (including some that the current object might not have)
I tried looking at the code NGUI used, but it was a bit too complicated for me to understand right now.
If you want to do it like in NGUI then use the tools that are available within NGUI itself and define a public variable like this:
public List<EventDelegate> DelegateList = new List<EventDelegate>();
With this, you can drop MonoBehaviour scripts in the Inspector field and can then select public methods/delegates contained in that script.
You can then invoke them like this:
void Start() {
EventDelegate.Execute(DelegateList);
}
Now every method in your delegate list will be invoked. You can see this for example in the UIButton script where this is used to handle the OnClick delegates.
I would like to drag button from one VBox to another.. is it possible to do that with JavaFx 2.2?
I found what I was looking for.
To get source object I'm using event.getGestureSource() method...
All I need to do is add this object to target
target.getChildren().add(event.getGestureSource());