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 Wach3D · Apr 20, 2016 at 08:04 AM · imagedisableenableactiveinactive

How to make a UI Image appear/disappear?

I want to press the key "I" on the keyboard and have an image appear and after pressing "I" on my keyboard again, the image will disappear.

This might be way more obvious than I think it is, but I've looked everywhere for hours and can't find anything.

C# or Javascript, I'm not picky!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
14
Best Answer

Answer by yapaysinek · Apr 20, 2016 at 09:38 PM

Successfully tested and works (for me) ;))

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class ImageShow : MonoBehaviour {
 
     public bool isImgOn;
     public Image img;
 
     void Start () {
 
         img.enabled = true;
         isImgOn = true;
     }
 
     void Update () {
     
         if (Input.GetKeyDown ("i")) {
 
             if (isImgOn == true) {
 
                 img.enabled = false;
                 isImgOn = false;
             }
 
             else {
 
                 img.enabled = true;
                 isImgOn = true;
             }
         }
     }
 }
 
Comment
Add comment · Show 7 · 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 Wach3D · Apr 20, 2016 at 10:45 PM 0
Share

It worked! I just gave up after attempting to write a bunch of scripts. Thanks! I really appreciate this, my game should be finished by tonight thanks to you!

avatar image yapaysinek Wach3D · Apr 21, 2016 at 07:22 AM 1
Share

Glad I could help! Good luck with the project :)

avatar image MagicStyle yapaysinek · Oct 24, 2017 at 02:21 PM 0
Share

Can't I just select the image by script? Or do I have to manually select it?!

avatar image ChenChi13 · Feb 22, 2018 at 10:14 AM 0
Share

super simple, thanks!

avatar image ars_longa · May 04, 2020 at 10:03 AM 0
Share

Heyo! First comment evar, yay. Just wanted to say you can do this even quicker using "!", which means "NOT" in C#. It's really useful for such little toggles because it allows you to change the value of the boolean to whatever it is not at the moment like so:

 if (Input.GetKeyDown(KeyCode.T))
         {
             img.enabled = !img.enabled;
         }

avatar image housayyn_r · Aug 02, 2020 at 08:04 PM 0
Share

i want to make it so that when i hold the button, the image disappears. this just toggles it on/off

avatar image Hellium housayyn_r · Aug 02, 2020 at 08:41 PM 0
Share
  using UnityEngine;
  using UnityEngine.UI;
  using System.Collections;
  
  public class HideOnKeyHold : $$anonymous$$onoBehaviour
  {
      public Image image;
      public KeyCode key;
  
      void Update ()
      {     
          img.enabled = !Input.GetKey(key);
      }
  }

avatar image
1

Answer by fatihcamci · May 20, 2017 at 08:48 AM

ı have a canvas with uı object but ı cant enabled and disable them.The are some question in my project.For example first question is true ı want to disable it and enable second one.I am looking for this questions for afew days but i couldnt find it :(((

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 fatihcamci · May 16, 2017 at 03:54 PM 1
Share

i wrote these: void tiklandiDogru() {

     GameObject.Find("Soru_Dragon").SetActive(false);

//above code works but below not works.i wonder at first Soru_Tiger is not active.it is not works because of this state.

     GameObject.Find("Soru_Tiger").SetActive(true);


     //gameObject.SetActive(!gameObject.activeSelf);

 }

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

64 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

Related Questions

Cant Disable Script on Another Gameobject 1 Answer

Why are Unity events so special? 1 Answer

Why doesn't enabling and disabling not work? 1 Answer

Disabling a certain image 3 Answers

How to activate an object after "x" seconds (C#)? 4 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