Simple Question Dialog in Unity! (Yes-No Ok-Cancel Unity Tutorial)

✅ Get the Project files and Utilities at unitycodemonkey.com/video.php...
🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games unitycodemonkey.com/gamebundle
🔴 RELATED VIDEOS 🔴
Simple Chat Bubble in Unity! (Chat, NPC, Multiplayer) • Simple Chat Bubble in ...
What are Delegates? • What are Delegates? (C...
Dynamic Tooltip in Unity! • Dynamic Tooltip in Uni...
How to Drag UI Windows and Send to Top in Unity • How to Drag UI Windows...
💬 Learn how to make a simple but extremely useful Question Dialog Window in Unity!
Perfect for asking the Player a question like "Do you want to Quit the game?", "Really change settings?" and so on. Also you can easily change the buttons from Yes/No to Ok/Cancel or anything else.
Since the Question Dialog works with Delegates it is super adaptable to any scenario.
🌍 Get Code Monkey on Steam!
👍 Interactive Tutorials, Complete Games and More!
✅ store.steampowered.com/app/12...
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
See you next time!
📍 Support on Patreon / unitycodemonkey
🎮 Grab the Game Bundle at unitycodemonkey.com/gameBundl...
📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
#unitytutorial #gamedev #unity #unity3d #unity2d #indiegame​ #gamedevelopment #madewithunity​ #indiedev​
--------------------------------------------------------------------
Hello and Welcome!
I'm your Code Monkey and here you will learn everything about Game Development in Unity using C#.
I've been developing games for several years with 8 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
I do Unity Tutorials on just about every topic, Unity Tutorials for Beginners and Unity Tutorials for Advanced users.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Other great Unity channels:
Unity - / unity3d
Brackeys - / brackeys
Dani - / @danidev
Jabrils - / @jabrils
BlackthornProd - / @blackthornprod
Sykoo - / sykootv
Jason Weimann - / @unity3dcollege
Jonas Tyroller - / @jonastyroller
--------------------------------------------------------------------
- Website: unitycodemonkey.com/
- Twitter: / unitycodemonkey
- Steam: store.steampowered.com/develo...

Пікірлер: 84

  • @CodeMonkeyUnity
    @CodeMonkeyUnity2 жыл бұрын

    ✅ Get the Project files and Utilities at unitycodemonkey.com/video.php?v=msCGC22vKQM ⚠Like someone mentioned there's actually an issue in the code kzread.info/dash/bejne/n6d3qaVrYtmxgbA.html&lc=UgzYhkw3tNmy1uPsPDR4AaABAg Normally I use my own custom Button class but here I used Unity's built-in Button which works in a different way. If you add a listener on ShowQuestion(); you will be adding more and more listeners every time you call the function which will make it call all previous Actions instead of just the Action on the last question. So instead you should make a YesBtnClick() and NoBtnClick(); and just add the listener once and in those functions you simply trigger the actions which you save as member variables instead of saving the button references. 🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses 🔴 RELATED VIDEOS 🔴 Simple Chat Bubble in Unity! (Chat, NPC, Multiplayer) kzread.info/dash/bejne/fWVnudCHfJS1ibA.html What are Delegates? kzread.info/dash/bejne/ZY6a2dOQnJC_eZM.html Dynamic Tooltip in Unity! kzread.info/dash/bejne/i4l90cp8iNfFoMY.html How to Drag UI Windows and Send to Top in Unity kzread.info/dash/bejne/f5Zm0deaY6nQiso.html

  • @Hazzel31337

    @Hazzel31337

    2 жыл бұрын

    if some one has implemented the changes mentioned above and is willing to share them with me i would be happy, because i have no clue how to do that ! :)

  • @Hazzel31337

    @Hazzel31337

    2 жыл бұрын

    @@riccardolupi3760 thanks

  • @riccardolupi3760

    @riccardolupi3760

    2 жыл бұрын

    @@Hazzel31337 I would remove all listener just before adding them: yesBtn.onClick.RemoveAllListeners(); noBtn.onClick.RemoveAllListeners(); yesBtn.onClick.AddListener(() => { Hide(); yesAction(); }); noBtn.onClick.AddListener(()=> { Hide(); noAction(); }); Hope it will work for you ;)

  • @javisin
    @javisin2 жыл бұрын

    Hi Hugo, happy to see this kind of tutorials back, as you said it :D

  • @nocturne6320
    @nocturne63202 жыл бұрын

    A few notes. I don't know how it is with UnityActions as I mostly use standard Actions, but there should be code to also remove the listener with the way you set it up, otherwise the callbacks will keep on piling up. With regular actions you are running a risk of null exceptions, or memory leaks when not explicitly removing them. I would definitely go with the way of assigning references in the editor trough [SerializeField] as with the Find function you are depending on the developer naming their gameObjects correctly. Personally, I would store the yes/no callbacks in a variable and have permanent OnYes, OnNo functions in the OnClick event that than call the callbacks stored in variables. That way there is only one callback added to each button and can be easily removed.

  • @yasirkula0

    @yasirkula0

    2 жыл бұрын

    Absolutely, this is the most crucial bug in the presented code right now. I hope people see your comment before using AddListeners.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Oh that's a good catch! I normally use my own Button class which automatically clears the previous reference but I changed it in the video to the built-in Button and totally forgot about that difference. Yeah with this Button the best approach would indeed be to define a YesBtnClick add the listener just once and inside trigger the Action. As for SerializeField vs Find, both can cause errors, you can forget to drag the reference with SerializeField or drag the wrong object. And with Find you can type in the wrong name. Personally I like to keep as much of my logic in the code as possibly so that's why I use Find, it prevents me from constantly having to switch back and forth between the Editor and the Code.

  • @dragonlord1935

    @dragonlord1935

    2 жыл бұрын

    @@CodeMonkeyUnity You should put something explaining this in a pinned comment so everyone can see since this IS kind of a big deal.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    @@dragonlord1935 Yup I've edited the pinned comment, thanks!

  • @dragonlord1935

    @dragonlord1935

    2 жыл бұрын

    @@CodeMonkeyUnity Thank YOU for actually listening and reacting to people's comments :)

  • @KalponicGames
    @KalponicGames2 жыл бұрын

    We want more videos like this each week :D. That is why we subscribed for. Thanks for making this video.

  • @brandoncoulombe5496
    @brandoncoulombe54962 жыл бұрын

    Hey this is exactly how I made the "yes or no" notification type at my Unity dev. job! To think just 3 years ago I was in school worshipping your tutorial videos... Not only did you teach me very specific things like how to make a minimap, you introduced many C# and Unity concepts (lambda expressions, tasks/jobs, actions, interfaces, scriptable objects, etc) early in my development, peaked my curiosity, and ultimately allowed me to accel. (And build some really awesome games in the process heheh!!) Thanks Hugo, I'm forever grateful 🙏♥️

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    That's great to hear! Thanks!

  • @HaTesful
    @HaTesful2 жыл бұрын

    This was pretty cool! Keep up the good work man

  • @MarushiaDark316
    @MarushiaDark3162 жыл бұрын

    Another really quick and useful tutorial. Thank you, senpai.

  • @firebiscuitgaming7624
    @firebiscuitgaming76242 жыл бұрын

    Great tutorial as usual. I pretty much built my confirmation dialogs the same way. One difference though is I prefer to bind the listener to the buttons only once (in onStart) and instead in ShowQuestion I assign the Action to a private var that is invoked when the listener is invoked. This is to prevent invoking the same listener multiple times.

  • @etherealregions2676
    @etherealregions26762 жыл бұрын

    I like how you break things into sections since it's easy to create reusable unity prefabs and modular scripts. I much prefer your style over the run on everything in one scripting style , you usually find in lower quality tutorials and books.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Thanks!

  • @arcday4281
    @arcday42812 жыл бұрын

    I like such video tutorials ! Now I understand the "delegates" a little better )))

  • @zehsofficial
    @zehsofficial2 жыл бұрын

    This video was very informative, thanks!

  • @rainwingp
    @rainwingp Жыл бұрын

    Great tutorial!

  • @CyberStudios
    @CyberStudios2 жыл бұрын

    Thank you for this, I have been battling to get my UI to do this, especially with chapter selection.

  • @Dzwalkthrough
    @Dzwalkthrough2 жыл бұрын

    So clear thank you 😀

  • @alijaras
    @alijaras2 жыл бұрын

    Cool video as always

  • @freezinfire
    @freezinfire2 жыл бұрын

    very cool, very helpful.

  • @castlecodersltd
    @castlecodersltdКүн бұрын

    Nice one. Thanks 🙂

  • @070tahsin
    @070tahsin2 жыл бұрын

    Very clean code thank you

  • @wise_old_tree
    @wise_old_tree2 жыл бұрын

    U help soo much

  • @kken8766
    @kken87662 жыл бұрын

    nice and easy ~ cheers~

  • @humadi2001
    @humadi20012 жыл бұрын

    All I can say is Thank You!

  • @ZackySalchichas
    @ZackySalchichas2 жыл бұрын

    Hi, I'm one of the first to see your video, greetings :)

  • @sundarakrishnann8242
    @sundarakrishnann82422 жыл бұрын

    Great!

  • @lee1davis1
    @lee1davis12 жыл бұрын

    Unity must watch tutorial

  • @catafest-work
    @catafest-work2 жыл бұрын

    If you want some simple tutorial ideas for the base menu: 1. simple custom background - I see a vignette effect; 2. creation of irregular polygons for GUI to obtain 3D effect. 3. some basic shaders for main menu;

  • @amansahu5512
    @amansahu55122 ай бұрын

    00:01 Creating a simple but useful question dialog in Unity 01:50 Creating customizable UI elements in Unity 04:00 Creating a simple dialog UI with yes and no buttons in Unity 06:01 Creating a Unity function to display a question with actions 08:03 Implementing a simple dialog with Yes-No options 09:57 Implementing a simple question dialog in Unity. 11:54 Implement simple question dialog in Unity for user confirmation. 13:44 Implementing simple question dialog in Unity Crafted by Merlin AI.

  • @alaslipknot
    @alaslipknot2 жыл бұрын

    Correct me if I'm wrong but I don't like what you did with the Awake method, why are you "finding" these component when you can just serialize these fields and just drag and drop and then save the dialogue as prefab ? there is nothing dynamic or unknown here, so there is no reason at all to make a "search", i know the performance is almost meaningless but one of the main reasons why i love this channel and had the bell notification ON is for how good the tutorials are from all aspect, and this kind of "rushed" code will encourage bad habits among beginners, I hope this didn't came up as offensive or anything, cheers!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    The reason is simply because I prefer to keep as much through code as possible so I don't have to constantly swap back and forth between code and the editor. This way all the logic is in just one place, the code. But yes if you like using the editor more often then sure make it a SerializedField and drag the reference instead of Find. Both approaches can cause errors, you can forget to drag the reference with SerializedField or you can mistype the name with Find.

  • @alaslipknot

    @alaslipknot

    2 жыл бұрын

    @@CodeMonkeyUnity I get your point, but the issue is not "forgetting" or a "typo", that's a "direct mistake" that could happen everywhere and anywhere, the issue is that we are doing a needless search for an object that is already serialized (a prefab) and the "bigger issue" is that in a learning channel you'd want to avoid bad habit as much as possible, but again, for this particular example the performance effect is almost meaningless, but you get my point.

  • @neelamshahi8630
    @neelamshahi86302 жыл бұрын

    Your name is Hugo I was in your stream

  • @MsDuketown
    @MsDuketown2 жыл бұрын

    Best is to have a (firsttime) setupwizard aviable before the OS is booting; so BIOS level. This architectural feature also allows for a complete new way to interact with settings, which are mostly .xml files.

  • @Venet89
    @Venet892 жыл бұрын

    5:01 Headphones warning, there's some serious volume mismatch!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Yeah sorry it seems I forgot to normalize that part, I had the microphone a bit far away so this video ended up much quieter than usual

  • @Extremogato123
    @Extremogato1232 жыл бұрын

    Hello Hugo, im wondering if you could make a video in a dialogue system but with voices, i mean how to manage the voice lines to play at a certain order and loading the sounds for the level

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    That is going to depend a lot on how complex you want it to be. It can be as simple as defining a Struct for the string text and the audioClip for the line, pretty much like I did on the simple audio video kzread.info/dash/bejne/g4Bmm8ONkZqwZbQ.html Or if you need something much more complex (possibly with tons of localization) then you would need something like a proper spreadsheet to organize the voice clips file names and dynamically load the line you want for the language you want.

  • @George-lb4gt
    @George-lb4gt2 жыл бұрын

    If you were to make it so the textbox would be triggered by a button what would you do?

  • @supertenchoo4271
    @supertenchoo42712 жыл бұрын

    Great Video Can you make video making simple inventory system

  • @arcday4281

    @arcday4281

    2 жыл бұрын

    It is already on the channel, but you will have to finish and combine it with other systems yourself )))

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    I made an inventory system quite a while ago kzread.info/dash/bejne/ZIuio7GPZ9Guh5M.html And more recently a Tetris Inventory System kzread.info/dash/bejne/mKyVpqR-Z5S7eKQ.html

  • @_sIash
    @_sIash29 күн бұрын

    make sure to remove all listeners from the yes and no buttons when the window is disabled or else multiple instructions will run simultaneously

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    27 күн бұрын

    Not sure what you mean, when the window is disabled the buttons aren't clickable so it doesn't matter if they still have logic attached

  • @mandev186
    @mandev1862 жыл бұрын

    sir build a procedurally Lod System or Give Some Idea To Me and sir very good live stream

  • @djjaysmith
    @djjaysmith2 жыл бұрын

    There is an issue here. Because you make the Dialog a Singleton and you use AddListener and never remove any listeners, then if you try to use this Dialog in multiple places you end up creating a long list of listener events which are triggered each and every time you call it. You don't see the problem in your code, because you only ever call the Dialog once and quit the application. I spent hours before I found this issue.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Oh good catch, sorry about that, I normally use my own Button class where I override the previous click function but for the video I went with the built-in button which does work differently.

  • @ketherclassbirb3555
    @ketherclassbirb35552 жыл бұрын

    As a very new person to both c# and unity, I was wondering when I created the c# script, I wasn’t able to connect it to the TectMeshPro, and it just came up as a blank word instead, is there any way to fix this?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    What do you mean "wasn't able to connect" ? You can't set the text? Why? NullReferenceException? unitycodemonkey.com/video.php?v=5irv30-bTJw

  • @ketherclassbirb3555

    @ketherclassbirb3555

    2 жыл бұрын

    @@CodeMonkeyUnity It worked! Tyvm

  • @In-N-Out333
    @In-N-Out3332 жыл бұрын

    Why add the listener in code instead of in the editor?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Sure you could make a YesBtnClick function and assign the event in the editor, personally I just prefer to keep as much as possible in the code, it prevents me from constantly having to switch back and forth between the editor and the code.

  • @Vishinho17

    @Vishinho17

    2 жыл бұрын

    Also this way allows you to call the Dialog from a class that isn't a Monobehaviour/Component. Or from an object that will be created or spawned during runtime.

  • @yasirkula0

    @yasirkula0

    2 жыл бұрын

    Another benefit is being able to use Visual Studio's "Find All References" functionality. If functions are added from the editor, later on you can't easily find which buttons were calling that function.

  • @kingbling7571
    @kingbling75712 жыл бұрын

    I can't :(((( I just can't wrap my head around your voice now, not after the face reveal, nooooooooooooooooo

  • @ChristopherRockhill
    @ChristopherRockhill2 жыл бұрын

    Where does “gameObject” com from in the line: ganeObject.SetActive(“false”); ?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    It's the game object where that script is attached to

  • @ChristopherRockhill

    @ChristopherRockhill

    2 жыл бұрын

    @@CodeMonkeyUnity thanks

  • @ilaanisdead
    @ilaanisdead2 жыл бұрын

    Code monkey, can you do a video on attaching a polygon collider on trail renderer please?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    LineRenderer can work in 3D whereas the PolygonCollider only works in 2D So you would need to go through the line renderer and grab all the generated points, convert them to 2D space and pass them to the PolygonCollider. There's no automatic way.

  • @ilaanisdead

    @ilaanisdead

    2 жыл бұрын

    @@CodeMonkeyUnity I mean the trail renderer not the Line Renderer

  • @Any1SL
    @Any1SL2 жыл бұрын

    This won't work on the new input system correct?

  • @Any1SL

    @Any1SL

    2 жыл бұрын

    Disregard. Just have to convert the event system and its good.

  • @sameoy696
    @sameoy696 Жыл бұрын

    How do I make the user himself put a question and answer true or false

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    I made an Input window here unitycodemonkey.com/video.php?v=4n6RT805rCc

  • @watercat1248
    @watercat12482 жыл бұрын

    How many times the ask the same question ? I mean what the point to ask twice if want to quit the game ?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    To prevent accidental clicks. Instead of asking to quit the game you can imagine asking the player if they really want to buy a really expensive upgrade.

  • @watercat1248

    @watercat1248

    2 жыл бұрын

    @@CodeMonkeyUnity personally I know how to make that system even but I use different code structure if want to do the same with different commands I never use delegate I don't even remember what the delegate do But havent create question like that because is not necessary yet but I believe wean I create my first networking game I will have questions like this in meny instant for example 1. Wean the player is afk for some time I will kick the afk player but before kick I will I will put message with timer that if player is afk if pres yes I will kick the player if press no I will stay on the game and don't press eny off this button and passage the time I kick for the server 2. also Wean Saman the have no indrntent contention in the middle of the game I will ask I semilunar question with the main difference thar the option I will by to Leave the game or try to reconnect

  • @thetanfox9147
    @thetanfox91472 жыл бұрын

    day something of asking for a pixel art editor in unity

  • @thefossilfinder6286
    @thefossilfinder62862 жыл бұрын

    First!

  • @rasul_dude
    @rasul_dude2 жыл бұрын

    Are you sure you want to quit the game? Yes Are you really sure? Yes Are you really really sure? Yes Really Yes Really

  • @jozimastar95
    @jozimastar952 жыл бұрын

    I just realized that I'm banned from Microsoft accaunt and also can't use c#)

  • @yuqzii

    @yuqzii

    2 жыл бұрын

    You can still use c#, but ig u cant use visual studio

  • @MrNobody_0000
    @MrNobody_00002 жыл бұрын

    ilk.d

  • @arcday4281
    @arcday42812 жыл бұрын

    private void Hide() { yesBtn.onClick.RemoveAllListeners(); noBtn.onClick.RemoveAllListeners(); gameObject.SetActive(false); }