How to Drag UI Windows and Send to Top in Unity

  Рет қаралды 35,739

Code Monkey

Code Monkey

Күн бұрын

Пікірлер: 93
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Here's an essential script for any game that uses a lot of windows! 🎮 Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel! ✅ Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php
@lukax6287
@lukax6287 3 жыл бұрын
Dividing by canvas.scaleFactor does not seem to work for me. Do you know why?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
@@lukax6287 Are you using a Screen Space canvas? Did you set the Canvas Scaler like I did?
@speedrob
@speedrob 5 жыл бұрын
Dude... loving the content, one of the top tier unity tutors on YT.
@jameslavery2958
@jameslavery2958 5 жыл бұрын
I can't tell you how useful your tutorials are to me personally. Awesome job, thank you.
@redditgems-dailyuploads3421
@redditgems-dailyuploads3421 5 жыл бұрын
Honestly, im so glad i found your channel, everything is explained perfectly, thanks !
@petelovagssecondaccount5291
@petelovagssecondaccount5291 5 жыл бұрын
Thanks for making tutorials on mechanics from your own games! It helps a lot!!
@anagr_
@anagr_ 5 жыл бұрын
Hi! Awesome as usual! 10:30 - instead of using "while" loop better use method GetComponetInParent( ) of the Component docs.unity3d.com/ScriptReference/Component.GetComponentInParent.html or GameObject.FindObjectOfType( ) docs.unity3d.com/ScriptReference/Object.FindObjectOfType.html The first one does the same things as your WHILE-loop but "out of the box". The second one goes from the top of the hierarchy to bottom and try to find the first occurrence of the needed type.
@-.._.-_...-_.._-..__..._.-.-.-
@-.._.-_...-_.._-..__..._.-.-.- 3 жыл бұрын
I need to watch more of your videos. I made this waaay more difficult than it should have been.
@serialchiller9183
@serialchiller9183 5 жыл бұрын
Thank you so much! You use KZbin in the best way! Also I love the intro :]
@kerandonovan7255
@kerandonovan7255 3 жыл бұрын
One of your best tutorials! Cheers.
@cosymonkey4572
@cosymonkey4572 5 жыл бұрын
this is exactly what ive been looking for! You rock
@srdjangrbic3506
@srdjangrbic3506 3 жыл бұрын
Hi! This video is awesome and it helped me a lot. Thanks. However, I do have a few more questions and those are: 1.) How can we resize the window by dragging its edges? 2.) How can we make minimize and maximize buttons? Thanks for your answer in advance :) .
@tigransahakyan2840
@tigransahakyan2840 5 жыл бұрын
Great as always) keep going )
@addisonknox5052
@addisonknox5052 4 жыл бұрын
Thank you Mr. Monkey. Great, simple tutorial.
@jasonb202020
@jasonb202020 4 жыл бұрын
Awesome as always!
@yahoruz
@yahoruz 4 жыл бұрын
hm the deviding by canvas scalefactor doesnt seem to work what could be the problem? double checked the code and adjusted it to the main project canvas?
@lukax6287
@lukax6287 3 жыл бұрын
Having the same problem
@janstachu7744
@janstachu7744 2 жыл бұрын
Same here
@epicei
@epicei 3 жыл бұрын
How would I best go about making it so you can click, drag and resize these windows?
@mypaxa003
@mypaxa003 5 жыл бұрын
Awesome tutorials, I like it)
@lee1davis1
@lee1davis1 5 жыл бұрын
Favorited this one. Very useful tut.
@hayesgeldmacher8592
@hayesgeldmacher8592 5 ай бұрын
very helpful stuff, thank you !
@breadzo
@breadzo 2 жыл бұрын
So helpful and easy! Thank you!
@sagiziv927
@sagiziv927 5 жыл бұрын
At 10:23 why didn't you use GetComponentInParent()¿🤔
@LynJuice
@LynJuice 4 жыл бұрын
Hey nice tutorial do you have a video for resizeing the window?
@maleinanderesprison3095
@maleinanderesprison3095 5 жыл бұрын
can you show,.. "UI can´t leave the screen" and "automatic adjustment of the size when adjusting the screen"? thanks for this awsome video
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Check out the Tooltip where I make it so it never leaves the screen kzbin.info/aero/PLzDRvYVwl53sN4Ewi_f-iyWZzWNmLG_bI
@maleinanderesprison3095
@maleinanderesprison3095 5 жыл бұрын
@@CodeMonkeyUnity Thank you! i love your content!
@elihucop
@elihucop 5 жыл бұрын
Hi Code! Thank you for the tutorial; i have a problem with the package this not loaded scripts in some objects in the scene
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
What objects are missing? The window drag script should all be there
@SimbaGtVr
@SimbaGtVr 4 ай бұрын
thank you so much for the script it helps out with my game a lot
@ASMRcu
@ASMRcu 5 жыл бұрын
Anthor Awsome tut. And Yup i use this technique to make custom UI for player...just like PUBG ..
@antonioiliev7485
@antonioiliev7485 4 жыл бұрын
Great tutorial. :)
@shadyismad9419
@shadyismad9419 3 жыл бұрын
How to make the windows resize if we drag the corners?
@donovansousa569
@donovansousa569 4 жыл бұрын
best tutorial !!! Thanks !!
@kostyayeremenko7904
@kostyayeremenko7904 3 жыл бұрын
clear and helpfull, thx bro
@roll_png2
@roll_png2 2 жыл бұрын
Hey guys quick tip is if you don't want it to be on top of other UI create a new canvas and place that canvas below the other UI canvas and boom
@Toopa88
@Toopa88 5 жыл бұрын
8:20 literally googled that today. I use OnMouseDown/-Up/-Enter/-Exit. Is that fine or should I use your method?
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
OnMouseDown uses colliders whereas OnPointerDown uses the EventSystem. If you're trying to click on a SpriteRenderer in your scene use OnMouseDown, if you're working with UI objects use the EventSystem interfaces.
@lukenukem8028
@lukenukem8028 3 жыл бұрын
This video makes me subscribe.
@MrLefthand3r
@MrLefthand3r 5 жыл бұрын
Hello! Do you have a video where you implementing a resizable UI windows?
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Haven't covered that yet, could be an interesting topic. If you use Unity's anchors it should be relatively easy, position all the children with their anchors and click and drag to modify the edges of the parent sizeDelta I'll look into it, thanks!
@MrLefthand3r
@MrLefthand3r 5 жыл бұрын
@@CodeMonkeyUnity i find this task pretty "gimmick" if you want to do it with 8 resize points (4 in corners and 4 in the middle of each side) and behave like in any "shape editor"
@457Deniz457
@457Deniz457 5 жыл бұрын
Rly usefull thanks ! :)
@__ian94__
@__ian94__ 5 жыл бұрын
At 10:16, wouldn't it be easier to use transform.root?
@Mixtrate
@Mixtrate 5 жыл бұрын
potentially depending on how you setup your hierarchy. If your canvas is not the root of your gameobject then I think root will not work.
@savinodelgiudice1848
@savinodelgiudice1848 Жыл бұрын
Thanks, it works great but if I wanted to make the panel stop within the edges of the canvas, how can I do?
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Do some math with the size of the window and check if the new position is valid, I did some window math in the Tooltip video for resizing it unitycodemonkey.com/video.php?v=YUIohCXt_pc
@OVXX666
@OVXX666 3 жыл бұрын
how come its not letting me assign the window to the rectTransform thing :( is it because im using sprites? its letting me assign some thing but not my whole window :(
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
RectTransform is a UI component so if you have a normal GameObject outside the UI it doesn't work with that
@venomradar
@venomradar 14 күн бұрын
Hey how would you make the window resizable during runtime with a cursor?
@CodeMonkeyUnity
@CodeMonkeyUnity 14 күн бұрын
Put invisible drag objects on all sides, then when the player clicks and drags change the size instead of moving it. I covered one way to change size in my Tooltip tutorial unitycodemonkey.com/video.php?v=YUIohCXt_pc
@venomradar
@venomradar 14 күн бұрын
@CodeMonkeyUnity thanks
@apubetico
@apubetico 5 жыл бұрын
hey code, thanks for the video i need some help. im doing a typing game, i have a list of strings showing in the canvas, when you type the correct word, it's deleted from the list. i want a way to have a color gradient for the list, being transparent at the top and full opaque at bottom. i've done a shader for a plane that is over the list to "fake" that degradation. but is not ideal. how would you do it?
@Golem1988
@Golem1988 Жыл бұрын
How does one prevent dragging UI window from the screeen and not getting it back on screen ever again? :D Asking this cause it may literally be the case.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
You could do some math using the width of the window and reposition it if it gets off screen, like I did with my tooltip tutorial unitycodemonkey.com/video.php?v=YUIohCXt_pc
@gamelucasdresch
@gamelucasdresch 4 жыл бұрын
Hi CodeMonkey, This is a good video, but I have a question. I have 4 windows, 1 fixed window and 3 drag windows. When I click on a drag window, that window is moved to the bottom of the list and appears in front of the other windows. How can I make sure that only this front window and the fixed window are not transparent? Sorry my bad english...
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
You can handle transparency with a CanvasGroup, then just keep all your windows in a List and do whatever logic you want with them
@Chrizzonator
@Chrizzonator 4 жыл бұрын
hey nice video. But what about preventing the UI to dragged outside of the screen ?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
The mouse itself should never be able to leave the screen. As for the window, you can look into how I did it on the Tooltip kzbin.info/www/bejne/rZjLo6qQabCEqMU
@Chrizzonator
@Chrizzonator 4 жыл бұрын
@@CodeMonkeyUnity I figured a solution for myself now but thx
@AdisonCavani
@AdisonCavani 3 жыл бұрын
@@Chrizzonator what's the solution for this problem?
@siisi4
@siisi4 4 жыл бұрын
thank you vm
@GiantBean
@GiantBean 2 жыл бұрын
Anyone know a way to make the scale or size of a window adjustable by the user? Not just scaling with the screen size or being able to scale the entire game window but scaling the window by clicking and dragging like you can do on a browser window or other PC windows?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
There's no automatic way, you have to manually handle that logic yourself. Capture clicks on the edges of the window, listen to while the mouse is held down, increase the size of the container, etc
@GiantBean
@GiantBean 2 жыл бұрын
@@CodeMonkeyUnity it would be great to get a tutorial on this as I can't find one anywhere.
@alleyesonme1432
@alleyesonme1432 4 жыл бұрын
Hi! Great vid, but how to make UI windows stay within canvas boundaries?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
You need to do some math based on the background size, similar to how I made with the Tooltip kzbin.info/www/bejne/rZjLo6qQabCEqMU
@kosta1570
@kosta1570 5 жыл бұрын
Use dark theme for code editor. You burned my eyes :D
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Sadly the dark editor burns my eyes
@kosta1570
@kosta1570 5 жыл бұрын
@@CodeMonkeyUnity try visual studio code with atom theme. its faster and better editor with amazing color palete. and theme is very nice.
@ibrahimrashwan
@ibrahimrashwan 5 жыл бұрын
Why not just using GetComponentInParent() it's much easier !??
@grumpysalmon4153
@grumpysalmon4153 Жыл бұрын
How can I restrict the windows to stay within screen bounds?
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Do some math with the window size and the Screen.width, I did something like that in the tooltip video unitycodemonkey.com/video.php?v=YUIohCXt_pc
@MGConstantin
@MGConstantin 5 жыл бұрын
What happens if you send a window off screen ? how do you deal with that ?
@yigithanion
@yigithanion 5 жыл бұрын
If you can drag your cursor out of screen, yes you can drag window out.
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
The cursor cannot leave the screen so that shouldn't ever happen. But you can add a simple position test when dropping the window.
@TypeZ3R0
@TypeZ3R0 5 жыл бұрын
Hi, I want a help about unity!! My question is, can I make a 2D or 2.5D with vector style graphics games with cool modern particle system particle effects, AI agents, vector graphics, 2D rendering, 2D physics effect in unity personal version (free) with a low budget HP laptop. With Intel quad core i3 CPU + Intel HD 4400 graphics and 4gb ram + windows 10 ? Plzz help me 🙏
@tomicooltomi
@tomicooltomi 5 жыл бұрын
Should be doable but the hardware specs are a bit low for overall game development.
@anagr_
@anagr_ 5 жыл бұрын
You can but it will be so painful.
@Toopa88
@Toopa88 5 жыл бұрын
4gb ram, Windows 10 and unity doesn't work together. You'll get so triggered at your laptop that you wanna throw it out of the window.
@Toopa88
@Toopa88 5 жыл бұрын
When you have a low budget laptop the first thing you should do is getting Linux. While it's bad for Unity you can do a lot of other stuff and things will run much smoother.
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
Unity is free so just try it out, that laptop is enough for you to start learning.
@Ziplock9000
@Ziplock9000 Жыл бұрын
ScreenPointToLocalPointInRectangle is a better 'universal' solution
@ReZpawner
@ReZpawner 5 жыл бұрын
The popups are kinda disturbing the flow of the video. Could you instead put the info in the beginning or after the video? I'm sure more people would like to check out those things if they weren't in the process of coding at the time. I'd love to know what games that you've made, but not in the middle of creating interface objects.
@CodeMonkeyUnity
@CodeMonkeyUnity 5 жыл бұрын
I always make sure the popups never block anything so you can follow along and not miss anything.
@ReZpawner
@ReZpawner 5 жыл бұрын
@@CodeMonkeyUnity They don't block anything, but they steal attention from the actual tutorial, breaking the concentration of the viewer. I can't speak for anyone but myself, but to me it had the opposite effect of what you're after. I went from "I want to know more about this author's games" to "well that was annoying, now what was I doing? Now I have to rewind." after it popped up. Personally I'd much prefer a "hey why not check out some of these games I made" at the end of the video. At that point I'm done with the work part, I could use a break, and I'm thankful for the lesson. I'd be much more inclined to check them out then.
@lefthand2
@lefthand2 4 жыл бұрын
o
Animation vs. Math
14:03
Alan Becker
Рет қаралды 79 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Simple Drag Drop (Unity Tutorial for Beginners)
10:31
Code Monkey
Рет қаралды 338 М.
Drag and drop in Unity UI - create your own inventory UI!
12:47
Coco Code
Рет қаралды 120 М.
Ability Bar in Unity (Swap Weapons/Items)
29:07
Code Monkey
Рет қаралды 33 М.
EASY Drag and Drop for UI - Unity Tutorial
9:51
samyam
Рет қаралды 18 М.
Implementing World Streaming in my Unity Game! | Devlog
9:16
Kyle Banks
Рет қаралды 45 М.
Modular Character System in Unity (Move, Attack, AI, Pathfinding)
21:16
I Made My First Game in Godot in 3 Weeks...
26:21
Jack Sather
Рет қаралды 491 М.
Simple Skill Tree in Unity (Unlock Abilities, Talents)
25:53
Code Monkey
Рет қаралды 83 М.
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41