Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Fewpwew130 · Feb 16, 2015 at 05:48 AM · buttonimageshow

Showing image, when a button is pressed

Hey! I am trying to create a GUI for mana resource. So I try to make an image disappear after a mouse button is pressed. I am not quite sure how to do it properly and I am asking for the advice.

The way I imagine doing it: I attach the script to the character. I parent canvas obejct to the character. I parent the image to the canvas (and manually adjust the position of the picture). Then in the script, I drag and drop my image, after that through scripting I disable and/or enable the image.

I suppose it should look like that, am I right?

  using UnityEngine;
     using System.Collections;
     
     public class imagescript : MonoBehaviour {
     
         public Sprite mana1;
     
         
         void Update () {
         
             if (Input.GetButton("Fire1")){
     
                 mana1.isEnabled == false;
             }
         }
     }
     
 

   

Thank you!

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 Fewpwew130 · Feb 16, 2015 at 07:15 AM 0
Share

Darsh2019, it works! Thank you very much!!! Please convert your comment to an answer, so I could upvote it!

avatar image Darsh2019 · Feb 16, 2015 at 08:53 AM 0
Share

your welcome.Let me know if you get any error.vote for the answer..

1 Reply

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

Answer by Darsh2019 · Feb 16, 2015 at 06:34 AM

if your Image is parent of canvas then there is problem because when you disable it by button press your canvas is also going to disable. So first remove your image as parent. -->after that: public Gameobject mana1; -->on button pressed mana1.setActive(false);

Save your script and drag and drop your image sprite.. hope this help. sry for bad ENGLISH.

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.

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

Clickable button area is offset 0 Answers

UI Image not blocking raycast 3 Answers

Animation Bug! 0 Answers

how do i make my button's source image bigger without changing the button hover/clickable area? 0 Answers

I want to make responsive homescreen. how to make responsive homescreen UI like this example ? 0 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