Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Mar 07, 2015 at 10:10 PM by KnightRiderGuy for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KnightRiderGuy · Jan 26, 2015 at 03:04 AM · uibuttonsui imagetoggleactivate

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

I have been trying to find a good simple way to simply turn on and off (Toggle) another UI image using a single UI button. Is there a simple way to do this?

Comment
Add comment · Show 2
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 zaid87 · Jan 26, 2015 at 03:14 AM 0
Share

The other image, do you show them by using a GUI function (something like DrawTexture) or do you made it a GameObject? The way to show/hide is somewhat different between the 2.

avatar image KnightRiderGuy · Jan 26, 2015 at 03:28 AM 0
Share

Just another UI image on a canvas, It's basically a lighted state for an indicator light to show when something is either active or not active but it's supposed to be turned on and off by a UI button also a child of the canvas. I hope that helps explain it better?

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by zaid87 · Jan 26, 2015 at 03:47 AM

I'm not familiar with using canvas but maybe something like this should do. Since from what I've seen, the image will still be a GameObject. I made the image to be public so you can assign it in the editor instead (drag&drop):

 public GameObject image;
 
 void OnGUI(){
    if(GUI.Button(new Rect(0,0,100,100), “Toggle Image”)){
        image.SetActive(!image.active);
    }
 }
Comment
Add comment · Show 1 · 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 KnightRiderGuy · Jan 26, 2015 at 05:11 AM 0
Share

Thanks, I didn't need the OnGUI part but the "image.SetActive(!image.active);" was the part of the puzzle I was missing, I used the public GameObject to set my image and the other part solved it. Thanks :)

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Buttons in unity: Text or Built in text in PNG? 2 Answers

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

Do Something ONLY when all Toggles are On or Off 4 Answers

Button intractable area larger than sprite image 1 Answer

How to disable button animation fade? 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