Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Rambolink94 · Oct 15, 2017 at 12:20 AM · uimenubuttonsui imageonclick

[Partially Solved] OnClick of one button, show different set of buttons.

I have figured out how to make different button menus show up based on an OnClick event. (The code is very long and there is definitely a better way to do do it. But, it works. (Code is located down below)) Thanks to all those who helped. All I did was set up a script for OnClick event sets a button menu active depending on the button clicked. Now, however, I am at another dilemma. I need the player to be able to add new buttons. For example, in the continent button category, when clicked it activates the right side menu. This menu lists all of the continent maps (each button displays a different map onClick). I need to allow the player to add new buttons that they can then attach a map image to. I know how to do an image attachment, I just need help understanding how to create new buttons that will be remembered each time the player opens the game. I imagine i'd use PlayerPrefs. Anyway, any help will be much appreciated. Thank you.

[Original Post] I have been trying to figure out this problem for hours, and I haven't gotten anywhere. What I am making is a menu system. There are several buttons in the menu system that each, when clicked, need to change the buttons of another menu to a different set of buttons. Make sense?alt text

As you can see in the pick, the left menu, under category, has several buttons. I need each of those buttons, OnClick, to list their own set of buttons on the right menu. I have a vertical grid layout for the menus, as well as a scroll rect. What is the best way for me to go about doing this.

Right now all I need is an understanding of how to show different buttons based on button clicked. However, later, I need to allow players to add and delete buttons based on what map categories they want to use. Sorry if this question is confusing, It's hard to even describe what my problem is. Feel free to ask questions if you don't understand my question.

Thanks you all!

[Code for Menu Set active]

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MapMenus : MonoBehaviour {
 
     public GameObject[] rightMenus;
 
     void Start() {
         foreach (GameObject rm in rightMenus) {
             rm.SetActive(false);
         }
     }
      
 
     // ****** !! THIS IS HORRIBLE CODE AND NEEDS WORK !! ******
     public void WorldMap() {
         foreach (GameObject rm in rightMenus)
         {
             rm.SetActive(false);
         }
         rightMenus[0].SetActive(true);
     }
     public void ContinentMap()
     {
         foreach (GameObject rm in rightMenus)
         {
             rm.SetActive(false);
         }
         rightMenus[1].SetActive(true);
     }
     public void CountryMap()
     {
         foreach (GameObject rm in rightMenus)
         {
             rm.SetActive(false);
         }
         rightMenus[2].SetActive(true);
     }
     public void ProvinceMap()
     {
         foreach (GameObject rm in rightMenus)
         {
             rm.SetActive(false);
         }
         rightMenus[3].SetActive(true);
     }
     public void CountyMap()
     {
         foreach (GameObject rm in rightMenus)
         {
             rm.SetActive(false);
         }
         rightMenus[4].SetActive(true);
     }
     public void CityMap()
     {
         foreach (GameObject rm in rightMenus)
         {
             rm.SetActive(false);
         }
         rightMenus[5].SetActive(true);
     }
     public void BuildingMap()
     {
         foreach (GameObject rm in rightMenus)
         {
             rm.SetActive(false);
         }
         rightMenus[6].SetActive(true);
     }
     public void DungeonMap()
     {
         foreach (GameObject rm in rightMenus)
         {
             rm.SetActive(false);
         }
         rightMenus[7].SetActive(true);
     }
 }

mapscreenshot.jpg (440.2 kB)
Comment
Add comment · Show 4
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 PizzaPie · Oct 15, 2017 at 11:15 AM 0
Share

Easiest way to go would be to create all buttons you may need, deactivate the second layer ones and when you click one of the active ones enable the second ones and disable the current.

 void OnClick(){
       foreach(GameObject go in CurrentButtons)
                go.SetActive(flase);
 
       foreach(GameObject go in ResultButtons)
               go.SetActive(true);
 }

But i don't remember if inactive UI elements are considered by the layout grid, if yes this would require to move them in/out of the group (change parent). On the other hand, personally i would create the max amount of buttons possibly active at once, and change their parameters according to what is needed, meaning i would keep in a script names (title of the button) and associated fuctions with OnClick event and set them via script on runtime. Cheers.

avatar image jchester07 PizzaPie · Oct 15, 2017 at 12:28 PM 0
Share

Inactive UIs are disregarded by layout grid.

avatar image Rambolink94 jchester07 · Oct 16, 2017 at 07:52 PM 0
Share

I'm so glad this is the case. Otherwise it would be a total pain!

avatar image Rambolink94 PizzaPie · Oct 16, 2017 at 07:51 PM 0
Share

Thank you for your help. This is exactly what I needed, and it worked well. However, rather than setting each button inactive/active, I set the entire menu inactive/active.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by unity_G2yrNlWYdpJKuw · Oct 15, 2017 at 04:43 PM

Well if you want to show buttons when you click a button, then just use the GameObject.SetActive

Comment
Add comment · Show 3 · 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 Rambolink94 · Oct 15, 2017 at 07:34 PM 0
Share

That would probably work, I just think all of those overlapping buttons would get very confusing and crowded. I'll keep that in $$anonymous$$d though.

avatar image unity_G2yrNlWYdpJKuw Rambolink94 · Oct 15, 2017 at 08:25 PM 0
Share

Well, you can create a pannel, then add buttons to that pannel as a child, then you can just turn the pannel on and off with the setactive. And name that pannel $$anonymous$$enu1 or something that will make it organized.

avatar image Rambolink94 unity_G2yrNlWYdpJKuw · Oct 16, 2017 at 07:35 PM 0
Share

That is a good idea. It makes more sense to deactivate an entire menu then each seperate button. Thank you for your help!

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.

Follow this Question

Answers Answers and Comments

124 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

Related Questions

Turn Another UI image on and off with a Single UI Button 1 Answer

Button intractable area larger than sprite image 1 Answer

Button highlighted a pushable without touching it 0 Answers

Runtime UI button creation: can't make an "OnClick" where I call a function from another script while sending a parameter. 2 Answers

Creating working UI Button from Script? 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