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 /
  • Help Room /
avatar image
0
Question by daant123 · Nov 20, 2016 at 08:33 PM · uieventtriggers

In Canvas, how do I require several triggers for a single event?

I am quite new to Unity and I feel that attempting to post any code might be a waste of our time. Basically, I am using Canvas to make a menu, and within that menu are several images that I want to have all be clicked on in order for a "secret menu item" to appear. I think I could get this working for a single item, but having multiple images to click has me lost. I have set up an Event Trigger with the EventTrigger.enabled function but I don't know how to translate that through code and with multiple clicks needing to be triggered in order for the secret button to appear. Any code or tips would be greatly appreciated. Thanks in advance.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dibbie · Nov 20, 2016 at 10:20 PM

Easiest way to achieve what your looking to do:

Have your "secret menu items" either on a seperate Canvas, or simply under a seperate hierarchy within your 1 Canvas - for example, you can create a Panel, turn off the Image component of it so the panel isnt seen (or set the alpha color of it to 0), then child all your "secret menu items set 1" to that panel -- basically the point is, you want to group your menus you want to essentially toggle, under different sections of your hierarchy in your Canvas or in a new Canvas completely, but you NEVER want to put Transforms or other things that are not UI elements in your Canvas's because it can mess them up sometimes and not show the children on the UI anymore when visible.

Then, you want to write a script, something along the lines:

 public GameObject[] hiddenMenus;
 
 public void ShowMenuItems(int hiddenMenuIndex){
 hiddenMenu.SetActive(true);
 }
 
 public void HideMenuItems(int hiddenMenuIndex){
 hiddenMenu.SetActive(false);
 }

Now, add a EventTrigger (click on your image you want to act as a "button" basically, click "Add Component", then go to "Event" (or type in the word "event"), then "Event Trigger") -- note youll have to do this one at a time, because EventTrigger doesnt support multi-editing (so you can select all your images and add the component, but you cant do anything with that component to all of them at once)

Then, click "Add New Event" or whatever the button says, and in your case, it sounds like youd want to add a "Pointer Click" event.

Leave the "Runtime only" line alone (this honestly really has no significant difference if you change it, you just dont need to worry about it in this case), then for the empty slot, you want to select the game object, that has this script you wrote on it -- you should really place this script on 1 object, like your main Canvas or your main Camera or something.

Now, set up your array on the object you placed the script on - select the little arrow for the array, give it a number, and then start setting the elements for each index of your array, to the game objects that hold the children of each of your hidden menus -- just remember the index or element number you put them at, so if you named your hidden menus in order by 1, 2, 3, and placed them in your array in that same order, itll be very easy to remember.

Then, go back to your image you want to act as a "button", the last section (the drop down) will become selectable, find your new script you wrote, and select the public function corresponding to what you want that button/image to do when clicked -- in that example, you probably want "ShowMenuItems", then set the number of what will be the 4th field, from 0, to whatever index you setup your menus on - this is where the memory comes in.

Once all that is done, if done correctly, you will be able to show different menus on different images you click on -- then you can apply the "HideMenuItems" as well to hide certain menus when you click on different images if youd so like.

Kind of a long-ish process that can be very confusing at first, but doing it in a "Event Trigger" way for each image, through one script with an array, is the easiest way I can think of doing what you want to do without over complicating the concept too much.

Hope this helped.

Comment
Add comment · Show 6 · 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 daant123 · Nov 20, 2016 at 10:52 PM 0
Share

First off, really appreciate the detailed response. It is kinda confusing, but considering it is the best answer if have been able to find online yet, I will go head first with attempting it. ;)

avatar image Dibbie daant123 · Nov 20, 2016 at 11:06 PM 0
Share

No problem, if you run into issues and cant figure it out, your welcome to email me or drop a reply, and ill see if I can get some visuals explaining the process to help you out.

avatar image daant123 · Nov 20, 2016 at 11:13 PM 0
Share

Do you know what could be causing this:

Assets/$$anonymous$$ain$$anonymous$$enu/Scripts/hidden$$anonymous$$enu.cs(9,28): error CS0117: hidden$$anonymous$$enu' does not contain a definition for SetActive'

?

avatar image Dibbie daant123 · Nov 21, 2016 at 12:38 AM 0
Share

Sounds like you called your script "hidden$$anonymous$$enu", and a variable also the exact same name, so its confused and basically trying to tell you that your script "hidden$$anonymous$$enu" (which is what it thinks your trying to use SetActive on), cant be done (because scripts dont use SetActive) -- so youd maybe want to name your variable different then the script name.

avatar image daant123 Dibbie · Nov 21, 2016 at 01:26 AM 0
Share

Wow, I'm a noob. I did that now I get:

Assets/$$anonymous$$ain$$anonymous$$enu/Scripts/secret$$anonymous$$enu.cs(9,25): error CS0103: The name `hidden$$anonymous$$enu' does not exist in the current context

and the same for line 12.

I'm sorry, if I could figure this out I would leave you alone :D

Any way you do give visuals to help? You would be the actual best.

Show more comments

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

106 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

Related Questions

Trigger events with bullets 0 Answers

Unity Event that returns mouse over 0 Answers

UI event with non-instantiated Prefab as event handler. What happens? 2 Answers

OnpointerClick not working(parents gameObject has EventTrigger) 0 Answers

[Solved] Scroll not working when elements inside have click events 3 Answers


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