How to Drag UI Windows and Send to Top in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2019
  • ✅ Get the Project files and Utilities at unitycodemonkey.com/video.php...
    Let's write some code to easily Drag a UI Window and Send it to the Top.
    Battle Royale Tycoon
    store.steampowered.com/app/85...
    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!
    🤖 Join the Community Discord / discord
    📦 Grab the game bundle at unitycodemonkey.com/gameBundl...
    📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
    #unitytutorial #unity3d #unity2d
    --------------------------------------------------------------------
    Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
    I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
    You can see my games at www.endlessloopstudios.com
    --------------------------------------------------------------------
    - Website: unitycodemonkey.com/
    - Twitter: / unitycodemonkey
    - Facebook: / unitycodemonkey

ความคิดเห็น • 88

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 ปีที่แล้ว +4

    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 ปีที่แล้ว +1

      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?

  • @redditgems-dailyuploads3421
    @redditgems-dailyuploads3421 4 ปีที่แล้ว +2

    Honestly, im so glad i found your channel, everything is explained perfectly, thanks !

  • @jameslavery2958
    @jameslavery2958 4 ปีที่แล้ว +1

    I can't tell you how useful your tutorials are to me personally.
    Awesome job, thank you.

  • @petelovagssecondaccount5291
    @petelovagssecondaccount5291 4 ปีที่แล้ว +3

    Thanks for making tutorials on mechanics from your own games!
    It helps a lot!!

  • @cosymonkey4572
    @cosymonkey4572 4 ปีที่แล้ว +1

    this is exactly what ive been looking for! You rock

  • @serialchiller9183
    @serialchiller9183 4 ปีที่แล้ว +1

    Thank you so much! You use TH-cam in the best way! Also I love the intro :]

  • @kerandonovan7255
    @kerandonovan7255 3 ปีที่แล้ว

    One of your best tutorials! Cheers.

  • @-.._.-_...-_.._-..__..._.-.-.-
    @-.._.-_...-_.._-..__..._.-.-.- 2 ปีที่แล้ว

    I need to watch more of your videos. I made this waaay more difficult than it should have been.

  • @speedrob
    @speedrob 4 ปีที่แล้ว +12

    Dude... loving the content, one of the top tier unity tutors on YT.

  • @addisonknox5052
    @addisonknox5052 4 ปีที่แล้ว

    Thank you Mr. Monkey. Great, simple tutorial.

  • @lee1davis1
    @lee1davis1 4 ปีที่แล้ว +1

    Favorited this one. Very useful tut.

  • @breadzo
    @breadzo 2 ปีที่แล้ว

    So helpful and easy! Thank you!

  • @anagr_
    @anagr_ 4 ปีที่แล้ว +3

    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.

  • @tigransahakyan2840
    @tigransahakyan2840 4 ปีที่แล้ว +1

    Great as always) keep going )

  • @jasonb202020
    @jasonb202020 4 ปีที่แล้ว

    Awesome as always!

  • @mypaxa003
    @mypaxa003 4 ปีที่แล้ว +1

    Awesome tutorials, I like it)

  • @kostyayeremenko7904
    @kostyayeremenko7904 3 ปีที่แล้ว

    clear and helpfull, thx bro

  • @donovansousa569
    @donovansousa569 3 ปีที่แล้ว

    best tutorial !!! Thanks !!

  • @srdjangrbic3506
    @srdjangrbic3506 3 ปีที่แล้ว +4

    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 :) .

  • @ASMRcu
    @ASMRcu 4 ปีที่แล้ว

    Anthor Awsome tut. And Yup i use this technique to make custom UI for player...just like PUBG ..

  • @antonioiliev7485
    @antonioiliev7485 4 ปีที่แล้ว

    Great tutorial. :)

  • @457Deniz457
    @457Deniz457 4 ปีที่แล้ว

    Rly usefull thanks ! :)

  • @lukenukem8028
    @lukenukem8028 2 ปีที่แล้ว

    This video makes me subscribe.

  • @LynJuice
    @LynJuice 4 ปีที่แล้ว +1

    Hey nice tutorial do you have a video for resizeing the window?

  • @siisi4
    @siisi4 3 ปีที่แล้ว

    thank you vm

  • @elihucop
    @elihucop 4 ปีที่แล้ว +4

    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  4 ปีที่แล้ว

      What objects are missing? The window drag script should all be there

  • @apubetico
    @apubetico 4 ปีที่แล้ว

    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?

  • @maleinanderesprison3095
    @maleinanderesprison3095 4 ปีที่แล้ว +4

    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  4 ปีที่แล้ว +1

      Check out the Tooltip where I make it so it never leaves the screen
      th-cam.com/play/PLzDRvYVwl53sN4Ewi_f-iyWZzWNmLG_bI.html

    • @maleinanderesprison3095
      @maleinanderesprison3095 4 ปีที่แล้ว

      @@CodeMonkeyUnity Thank you! i love your content!

  • @epicei
    @epicei 3 ปีที่แล้ว +2

    How would I best go about making it so you can click, drag and resize these windows?

  • @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

  • @kosta1570
    @kosta1570 4 ปีที่แล้ว

    Use dark theme for code editor. You burned my eyes :D

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      Sadly the dark editor burns my eyes

    • @kosta1570
      @kosta1570 4 ปีที่แล้ว +1

      @@CodeMonkeyUnity try visual studio code with atom theme. its faster and better editor with amazing color palete. and theme is very nice.

  • @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

  • @shadyismad9419
    @shadyismad9419 3 ปีที่แล้ว +1

    How to make the windows resize if we drag the corners?

  • @yahoruz
    @yahoruz 4 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

      Having the same problem

    • @janstachu7744
      @janstachu7744 2 ปีที่แล้ว

      Same here

  • @Toopa88
    @Toopa88 4 ปีที่แล้ว +1

    8:20 literally googled that today. I use OnMouseDown/-Up/-Enter/-Exit. Is that fine or should I use your method?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      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.

  • @gamelucasdresch
    @gamelucasdresch 3 ปีที่แล้ว

    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  3 ปีที่แล้ว

      You can handle transparency with a CanvasGroup, then just keep all your windows in a List and do whatever logic you want with them

  • @MrLefthand3r
    @MrLefthand3r 4 ปีที่แล้ว +1

    Hello! Do you have a video where you implementing a resizable UI windows?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      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 4 ปีที่แล้ว

      @@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"

  • @alleyesonme1432
    @alleyesonme1432 3 ปีที่แล้ว

    Hi! Great vid, but how to make UI windows stay within canvas boundaries?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      You need to do some math based on the background size, similar to how I made with the Tooltip th-cam.com/video/wghrwZ4KQrc/w-d-xo.html

  • @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

  • @sagiziv927
    @sagiziv927 4 ปีที่แล้ว +1

    At 10:23 why didn't you use GetComponentInParent()¿🤔

  • @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 ปีที่แล้ว +1

      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.

  • @Golem1988
    @Golem1988 7 หลายเดือนก่อน

    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  7 หลายเดือนก่อน

      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

  • @ibrahimrashwan
    @ibrahimrashwan 4 ปีที่แล้ว +1

    Why not just using GetComponentInParent() it's much easier !??

  • @Chrizzonator
    @Chrizzonator 4 ปีที่แล้ว

    hey nice video. But what about preventing the UI to dragged outside of the screen ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      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 th-cam.com/video/wghrwZ4KQrc/w-d-xo.html

    • @Chrizzonator
      @Chrizzonator 4 ปีที่แล้ว

      @@CodeMonkeyUnity I figured a solution for myself now but thx

    • @AdisonCavani
      @AdisonCavani 3 ปีที่แล้ว

      @@Chrizzonator what's the solution for this problem?

  • @Ziplock9000
    @Ziplock9000 ปีที่แล้ว

    ScreenPointToLocalPointInRectangle is a better 'universal' solution

  • @__ian94__
    @__ian94__ 4 ปีที่แล้ว +1

    At 10:16, wouldn't it be easier to use transform.root?

    • @Mixtrate
      @Mixtrate 4 ปีที่แล้ว

      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.

  • @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 4 ปีที่แล้ว

    What happens if you send a window off screen ? how do you deal with that ?

    • @yigithanion
      @yigithanion 4 ปีที่แล้ว

      If you can drag your cursor out of screen, yes you can drag window out.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      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 4 ปีที่แล้ว

    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 4 ปีที่แล้ว

      Should be doable but the hardware specs are a bit low for overall game development.

    • @anagr_
      @anagr_ 4 ปีที่แล้ว

      You can but it will be so painful.

    • @Toopa88
      @Toopa88 4 ปีที่แล้ว

      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 4 ปีที่แล้ว

      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  4 ปีที่แล้ว +1

      Unity is free so just try it out, that laptop is enough for you to start learning.

  • @ReZpawner
    @ReZpawner 4 ปีที่แล้ว

    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  4 ปีที่แล้ว +2

      I always make sure the popups never block anything so you can follow along and not miss anything.

    • @ReZpawner
      @ReZpawner 4 ปีที่แล้ว

      @@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