Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Runtime context menu og sidebar with buttons

Discussion in 'General Discussion' started by Jamsa78, May 4, 2022.

Thread Status:
Not open for further replies.
  1. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Hi

    We need to have either a context menu or a sidebar with buttons for our product.

    As as quick'n'dirty solution for a unity-noobish dev, how would I do that when it has to work runtime?

    Just to be completely clear: This is NOT for use in the Unity Editor, but "in game".
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,323
    Just script the usual unity ui. Detect context click then spawn or unhide the menu and move it to the right spot. You can animate sliding in/out by controlling UI position.
     
  3. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Thanks for your reply, but we need to go several steps back here. :D

    I know how to handle clicks, but I have no knowledge on how to make any "windows" in unity...
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,323
    With uGui.
    https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/index.html

    You make a canvas.
    Place a panel there, set its anchors and position.
    Place buttons for it as childre.

    That's a window.
    If you want it to support drag, you script it.
    If you want it to support resizing, you script resizing, and design UI with Vertical/Horizontal layout groups.
    -------
    Alternatively you can make UI out of sprites. Whichever is easier for you.
     
  5. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Hmm, well, I've made a canvas, but it's HUUUUGE and I can't change the size?

    How do I do that?
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,323
    MadeFromPolygons and Jamsa78 like this.
  7. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Sorry, I was too fast. :p Yeah, I checked the docs and found a way to resize it, yay. :)

    And I've added a button - and made that small as well.

    However the text "button" is still huge, and I can't find a place to change it? And yes, I've checked the docs you linked. ;)
     
  8. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,883
    Because the text would be on a game object that's a child of the button with a text component on it.
     
    Jamsa78 likes this.
  9. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    So it is! :D

    Thanks! :)
     
  10. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Hmm, so I've got the button and it's text looking ok.

    But the colors of the different states (normal, highlighted, pressed) doesn't apply. Why is that?
     
  11. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,877
    Rather than asking for help with literally every step of the way, why not try and actually learn how to use the UI system first before tackling this? You clearly need to go through some tutorials, instead of expecting to be handheld the entire way

    https://learn.unity.com/tutorial/ui-components

    https://www.raywenderlich.com/6570-introduction-to-unity-ui-part-1

    Google "Unity UI tutorial" and that will give you tons of results.

    Good luck :)
     
  12. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    While I agree that sounds best, sadly I don't learn very well that way.

    I need it to be specific for my project.
     
  13. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,883
    No one's going to hold your hand every step of the way. That's not the point of these forums. This is more or less basic stuff I learnt in month 1 of learning Unity.

    There's a million resources out there. Use them.
     
    Amon, Ryiah and MadeFromPolygons like this.
  14. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
  15. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,877
    Im not sure what you are getting at by throwing the rules out randomly in this thread, but the fact that nobody is going to hand hold you also hasnt changed.

    There is literally a rule about low effort in the link you provided - did you read the rules yourself before posting them?
     
    Last edited: May 5, 2022
    Amon and Ryiah like this.
  16. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,907
    Please read the code of conduct again, especially these:
    You can find the proper topic here. Although the comment about you need to at least start to learn yourself still stands. If you need a tutor, hire one, the forum is not a tutor service. But if you put in the work and just stuck somewhere, you're welcome to ask educated questions, we're glad to help.
     
    Last edited: May 5, 2022
    Amon, Ryiah and MadeFromPolygons like this.
  17. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,968
    Closed, wrong forum and low effort.
     
Thread Status:
Not open for further replies.