Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
This question was closed Oct 19, 2016 at 08:26 PM by Zitoox for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Zitoox · Oct 18, 2016 at 05:14 AM · script.ui imageenable

Enable Image

Okay, as no one understood my recent question, i am going to be short and precise:

How do i enable an UI Image via script?

Because i have tried everything, and i can't make this work! And why is there a script in both the wiki AND the documentation that literally doesn't work? that's it, thanks.

Comment
Add comment · Show 10
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 gjf · Oct 17, 2016 at 11:52 PM 1
Share

if you found a script in the wiki & docs, why not share with everyone so it can get fixed?

where's the script that you've tried? you're more likely to be helped if you show that...

avatar image Zitoox gjf · Oct 18, 2016 at 09:57 PM -1
Share

Because the last time i did that, no one even tried to edit. Also, the Unity documentation can only be edited by it's webmasters. And probaly the same applies to the wiki.

avatar image tanoshimi Zitoox · Oct 19, 2016 at 06:21 AM 0
Share

Anybody can edit a wiki, that's kind of tbe definition. Only Unity Tech can edit the docs... but how will they know that it needs editing if nobody points out mistakes?

Show more comments
avatar image Lilius · Oct 18, 2016 at 08:08 AM 0
Share

Enable the component or set active the gameobject or both. (In case your image is not enabled and you activate gameobject, theres nothing. And if you enable image while gameobject is not active, theres nothing.)

 myImage.enabled = true;
 myImageObject.SetActive(true);
avatar image Zitoox Lilius · Oct 19, 2016 at 02:54 PM 0
Share

I did that

 #pragma strict
 
 var Img : UI.Image;
 
 function OnTriggerEnter (other:Collider)
 {
         Img.enabled = false;
         Img.SetActive(true);
 }

And nothing happens. I get the error is not a member.

avatar image Lilius Zitoox · Oct 19, 2016 at 03:11 PM 0
Share

I don't understand what you are saying and I don't know how you tried to do it. You should share more about whats going on, like full error messages.

Does this change anything? var Img : UnityEngine.UI.Image; ??

Show more comments
Show more comments

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Zitoox · Oct 19, 2016 at 08:26 PM

After days trying to reach an answer and failing miserably, i finally fixed it BY MYSELF. I needed to ask the same thing almost 3 times in different ways because no one even try to read my questions and already start to insulting me. I was literally insulted 2 times and all my comments were negativated.

Keeping your ignorance aside, i am going to paste here the fixed code.

 #pragma strict
 
 var Img : UI.Image;
 
 function Start()
 {
     Img.enabled = false;
 }
 
 function OnTriggerEnter (other:Collider)
 {
     Img.enabled = true;
 
     if (Time.timeScale == 1.0)
         Time.timeScale = 0.0;
     else
         Time.timeScale = 0.0;
 }
 
 
 function Update () {
 
     if (Input.GetKeyDown ("p")) {
         if (Time.timeScale == 0.0)
             Time.timeScale = 1.0;
         else
             Time.timeScale = 1.0;
 
         Img.enabled = false;
     }
 }

This code need to be inserted on a gameobject with a collider and the "is trigger" checkbox enabled. Just drag an UI Image to the Img variable and that's it. When the player hits the gameobject's collider, it will show the UI Image and completely pause the game. Also, the script adds a unpause function to the game. In my case, i already had a pause function, so this works fine. To unpause the game and resume playing, just press P. The game will be resumed and the image will disappear.

UPDATED FIXED WORKING.

Comment
Add comment · Show 8 · 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 danivdwerf · Oct 19, 2016 at 08:43 PM 0
Share

@Zitoox I'm glad you got it working, but if your question is "How do i enable an UI Image via script", you can't espect us to tell you how to get an OnTriggerEnter function to work. Also tell it if you're working in javascript, the syntax is different from real code.

P.S. don't work in javascript

avatar image Zitoox danivdwerf · Oct 19, 2016 at 08:52 PM 1
Share

I am sorry, i was really angry because my engine was bugging and i couldn't make anything work correctly, and some people were annoying me so much that i didn't even noticed that i didn't put these basic things. But i think it wouldn't change that much because i already had a question a day before that explained everything, ahh i just don't know. Anyway, i am so happy that i finally made the script work! I was trying to make a thank you letter appear to the players, it's my first game ^.^

Why don't work with javascript? =|

avatar image danivdwerf Zitoox · Oct 19, 2016 at 10:33 PM 0
Share

It's starting to go the same route as actionscript (not as bad, but it's getting there).

Also, even though the differences are not the biggest, it's still better to learn a C language for when you go to other engines later on (even tough Unity does 70%).

The first thing my professors on my developing study was: "It's good to know a lot of languages, but we are not going to $$anonymous$$ch you javascript. You are not going to use that".

Show more comments
avatar image Lilius · Oct 20, 2016 at 05:17 AM -1
Share

No one insulted you. Don't take this as an insult. If you would have posted the code you tried, the error you got and reference to the documentation that was not working, you would have had a solution within few $$anonymous$$utes. If you post just one line of code and say: "i still get the "is not a compoent" thing." and the error actually comes from another line no one can tell the answer. Then you call me an idiot, which is an actual insult, because you didn't even show me the line that caused the error, then you ninja edit it, still refusing to tell the error and expect me to write a script to see the error. In my first comment I told you how to enable UI image, which was correct answer for your short and precise question.

avatar image Zitoox Lilius · Oct 20, 2016 at 02:35 PM 1
Share

I am talking about the other questions, and don't complain about it because you were rude. and i did show the image but you said that you couldn't see it. C'mmon, how are you expecting me to show an image AND to REPOST IT BECAUSE YOU CAN'T SEE IT? And i said the error like 6 times! And it was probally you that negativated my comments JUST BECAUSE you didn't even know what you was doing! And i warned that i was enraged. danidvdwerf made a script to show me, and that helped me to understand more about what was wrong. You just literally made two lines that doesn't even worked and failed at being an example.

avatar image Lilius Zitoox · Oct 21, 2016 at 02:18 PM 0
Share

Who down voted me and gave upvote to this? You seriously claim that these don't work? myImage.enabled = true; myImageObject.SetActive(true);

Show more comments
avatar image
1

Answer by danivdwerf · Oct 18, 2016 at 08:20 AM

you should try this:

using UnityEngine;
using System.Collections;
public class OHWOW : MonoBehaviour 
{
        [SerializeField]private GameObject myImage;
        private void Start()
        {
                myImage.setActive(false);
        }
        private void MakeItVisible()
        {
                myImage.setActive(true);
        }
}
Good Luck!
Comment
Add comment · Show 3 · 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 Zitoox · Oct 19, 2016 at 08:37 PM 0
Share

Thanks, but i figured out that Ui Images doesn't work with set active, just with enable.

avatar image danivdwerf Zitoox · Oct 19, 2016 at 08:43 PM 0
Share

That's why I put GameObject ins$$anonymous$$d of UIImage ;)

avatar image IsouEU · Dec 28, 2021 at 11:10 AM 0
Share

I already set it as Image and not as Gameobject because i need to set this size... .enabled does not working if i re-declare it as a gameobject too its ok to use .setactive

realy we need some lucky to work with unity...

Follow this Question

Answers Answers and Comments

60 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

Related Questions

Having trouble disabling and enabling game objects 0 Answers

script enable=false 3 Answers

How to disable my buttons when i press and enable the other ones? 0 Answers

How to show questions with corresponding image.,Unity Live Tutorial Quiz Game, how to make the text question into an image question 0 Answers

How to enable and disable a script on an game object by pressing a keyboard button? 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