• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ComedicSoldier · Nov 09, 2021 at 02:16 PM · uigameobject

How to open up a menu? 3D

Hello, I'm new to unity and am currently trying to figure some things out. As of now, I kind of have movement down. Now, that out of the way. I have a game object that I call a Terminal, and with this Terminal I wish to open a menu from it, like a chest or skill tree. I've done some searching around and have some ideas but none have worked thus far. If anyone has any ideas or can provide any help that would be most appreciated!

(This is the code I currently have. There's more above but I can't seem to fit it in the box below)

 //Entering Trigger
 void OnTriggerEnter(Collider other)
 {
     //Terminal lights up
     Renderer render = GetComponent<Renderer>();
     render.material.color = Color.blue;
 }

 //This is where the Menu would be opened up at
 void OnTriggerStay(collider other)
 {
     if (Input.GetKeyUp("e"))
     {

     }
 }

 //Exiting Trigger
 void OnTriggerExit(Collider other)
 {
     //Terminal turns off
     Renderer render = GetComponent<Renderer>();
     render.material.color = Color.black;
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ComedicSoldier · Nov 09, 2021 at 04:53 PM

@jmfp92 thanks for the feedback, I'll look into it for sure! And as of now, I'm just trying to get something to happen when I click E while in the trigger. I'm pretty sure I could figure out how to make on object change color when I click it, but Have not a single clue as to how I'd get a UI menu to pop up, not to mention to then close it.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jmfp92 · Nov 09, 2021 at 05:16 PM 0
Share

As I said you can treat ui components in the hierarchy as regular game objects. So something like

 GameObject menu;
 
 Void Toggle(){
     menu.SetActive(!menu.activeself);
 }

Then just call the Toggle function whenever you press E. Again, this really depends on how you’re designing it but this should help

avatar image jmfp92 · Nov 09, 2021 at 05:24 PM 0
Share

Here is a great video that will probably help. https://youtu.be/zc8ac_qUXQY

avatar image
0

Answer by Vilhien · Nov 09, 2021 at 02:48 PM

@ComedicSoldier I have a craft menu in my game, it works based on a drop-down list. I'll see if I can explain it's been a week since I got into my project. It really basically is all text based in my project, however you make a drop-down menu and when you select something the second time it tries to make it. alt text

alt text


1.jpg (59.7 kB)
2.jpg (79.6 kB)
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vilhien · Nov 09, 2021 at 03:01 PM 0
Share

Really depends on how you want to setup a craft menu. What do you visualize in terms of how you want it to work?

avatar image Vilhien · Nov 09, 2021 at 03:08 PM 0
Share

As stated above you could make a grid based image object and have things you click on.. In my project I'm trying to get it to add items to the list based off of when you come up with recipes by experiments for example. So you can either look at this problem like, do I make the code say add this item and this item.. Or do I have the play type in recipes they find? Or do I allow the player to make anything custom completley? The later would be the best.. But then you can expect needing to have a slated craft window like $$anonymous$$ecraft.. Still limited... Can you type craft slingshot, yes, can you type craft shotgun.. yes.. Text is more versitile but you have to.. access it then reaccess it..

For example in shot 4 bottom right the inventory is shown. just text. But you could click on a recipe, and it checks the string in your inventory and it could make anything.

avatar image Vilhien · Nov 09, 2021 at 03:16 PM 0
Share

The main thing is as stated above to access the object and make it active or inactive. You will want to make whatever your menu will look like then make it inactive. Then when you access it by hitting e or etc, make that item active. Then when you are done using it make it inactive.

You can do this by making a public gameobject reference usually and have the object dragged into this field.

However with UI you will need to add a specific class reference to the beginning of your script for all UI scripts to work. I would suggest looking up UI use in unity. You should see what I'm talking about.

avatar image Vilhien · Nov 09, 2021 at 03:18 PM 0
Share

The main thing is as the previous person stated, there are a lot of ways to do it. It depends really on what aesthetic and how you want it to work. In my case I started with a text string only where you typed craft slingshot for example. But then I modified it to where it would show the recipes as well and you could click them.

avatar image ComedicSoldier Vilhien · Nov 09, 2021 at 05:18 PM 0
Share

@Vilhien Thanks for the additional info, of what I can gather, your saying to attach the UI to the Object to then open to the player? I think I get what your saying but not quite. Even if I did, I hardly know C#, I use to do Java Script which isn't to big of a jump but nonetheless I'm still constantly confused.

avatar image
0

Answer by jmfp92 · Nov 09, 2021 at 02:25 PM

You’re probably going to have to search around for exactly what you want. There are a TON of videos on YouTube as well… but you typically go to the heirarchy, right click> UI> panel to get a large panel that holds an image. What I usually do is have one big panel that other components are children of and then write my code around that. You can treat ui objects in the hierarchy like any other game object, so building functions to toggle them on and off with SetActive() is fairly easy but here is the docs for UI https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/index.html . Most of the “making things show on screen” part is done in the hierarchy not through code. At least until you get a better understanding on how to access everything with code but that’s really just trial and error. Hope that helped!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

271 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

When to use UI and when to use GameObject in Unity? 0 Answers

How to make UI(Gameobject) appear on collision enter? 0 Answers

Display UI under the actual "Gameplay"? 3 Answers

UI interaction with GameObject,interacting between gameObject and UI panel 0 Answers

gameObject.setActive not working even though function gets triggered 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges