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 kostasandre · Feb 20, 2015 at 12:28 PM · uiimagehide

How to enable and disable raw image on ui system

Hello everyone, I have made a canvas with a raw image at the top right corner. My image is a key, what i want to do is when i pick up the real key, in my main game, to show up the picture at the corner and when i use the key to unlock a door for example the image to be disabled from the corner so i cant see it.

I have a picture that shows the canvas at the top and the main game at the bottom. So as u can see i dont want the image to be shown at the start of the game but when u pick up the key alt text

Here is my key control code which is a simple counter to know if i got the key or not and with o collider so the player can destroy it:

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class KeyController : MonoBehaviour {

 public GameObject keygot;
  
  
  
 void Start(){
  
 }
  
 void OnTriggerEnter(Collider collider){
 if (collider.gameObject.name == "Player"){
 PublicVariables.KeyCount+=1;
  
  
  
 Destroy (gameObject);
 }
 }
  

}

στιγμιοτυπο-οθονης-3.png (426.5 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Flazone · Feb 20, 2015 at 01:31 PM

Hi,

In your KeyControler code, try to declare a public variable who take the image of your Canvas.

 public Image keyImage;

alt text

Make a code who enable this image when you pickup the key and disable it when you use it.

 keyImage.enabled = true;

or

 keyImage.enabled = false;

This is just a proposition, I think there is many ways to do that. :)


key.png (1.3 kB)
Comment
Add comment · Show 2 · 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 kostasandre · Feb 23, 2015 at 12:59 PM 0
Share

Hi, Thanks for your answer, i have already tried that before but i cant drag and drop the image on the canvas when i make a bublic image.I can only drag the picture if my public variable is a gameobject and if i do that the enable and disable command wont work. :(

avatar image Flazone · Feb 23, 2015 at 05:51 PM 0
Share

Hi,

You need to use the UI 4.6 Image component :

alt text

GameObject -> UI -> Image

I made a little script that makes disappear an image if you press E

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class test : $$anonymous$$onoBehaviour {
     
     public Image testImage;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.E)){
             testImage.enabled = false;
         }
 
     }
 }
 

You just need to drag/drop your image on the public variable in the inspector. It works for me !

image.png (10.1 kB)
avatar image
1

Answer by kostasandre · Feb 24, 2015 at 12:17 PM

Ok i found the solution finaly..!! :D When i uploaded the pictures they are set at texture type as textures...i changed that to sprite 2D and everything works fine now.. :D Thanks for ur time.

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 Flazone · Feb 24, 2015 at 04:19 PM 0
Share

Oh well! Sorry I didn't think about that..

Good luck for the rest!

avatar image
0

Answer by kostasandre · Feb 24, 2015 at 12:17 PM

Hello again and thanks for your time. As u said i made GameObject ->UI ->Image and followed ur instructions my problem again is that for a reason i cant drag and drop my image if my variable is public Image ,i can only do that if i set it as public GameObject.

alt text

i followed what u said and smth i am missing and cant find what is it.. :( From my assets im trying to drag and drop the key2 picture to the key Image inspector which is set as public image KeyImage.

*When i first created gameObject->UI->RawImage i could drag and drop it right on the canvas at my scene as the first post ive made,now i cant either do that.


στιγμιοτυπο-οθονης-4.png (498.0 kB)
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

RenderTexture does not render canvas image. 0 Answers

UI Escape menu script not working. 2 Answers

How do you automatically fit a child of a layout group to the parent without it adjusting to fit its own contents? 1 Answer

UI Layering Problem! 2 Answers

Ui scaling 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