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 /
avatar image
0
Question by surfuay · Dec 11, 2018 at 12:55 AM · buttonsetactiveenableenabledshop

works with gameObject but not with Image SetActive vs Enabled

so when i use this code it works perfectly on SetActive for gameObjects instead of Enabled for UI Images.

I would love to just use gameObjects but they don't scale well with the UI elements and I can't seem to get the gameobjects to anchor properly. (i will gladly accept an answer to this instead of the following if it's easier).

it's disabling the 50 image on press but it's not enabling the 200 image.

what is wrong with my code that is not enabling the "200" element

public void BetterShield() { if (ShopUIManager.shopUIManager.ShieldUpgrade50Vis == true) {

             ShopUIManager.shopUIManager.ShieldUpgrade50Vis = false;
             ShopUIManager.shopUIManager.ShieldUpgrade50.enabled = !ShopUIManager.shopUIManager.ShieldUpgrade50.enabled;
             ShopUIManager.shopUIManager.ShieldUpgrade200Vis = true;
             ShopUIManager.shopUIManager.ShieldUpgrade200.enabled = !ShopUIManager.shopUIManager.ShieldUpgrade200.enabled;
         }
     }
 }
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 Vega4Life · Dec 11, 2018 at 01:10 AM 0
Share

Why can't you SetActive on your UI elements? They are gameObjects. The UI images only difference is they use a rect transform. $$anonymous$$aybe I am misunderstanding.

avatar image surfuay · Dec 11, 2018 at 01:28 AM 0
Share

so if I use an image and I do the logic on that last part, where it currently says "enabled", if I try and put the line "SetActive" it comes back as an invalid line. so I assume if I have an Image I cant use attractive. but if I try to do the gameobjects when its built and put on a device other than the editor it's not in the right place, because the gameobjects dont have anchors that I can use on them.

avatar image Vega4Life surfuay · Dec 11, 2018 at 01:37 AM 0
Share

Right, because you need to call it like this:


 ShopUI$$anonymous$$anager.shopUI$$anonymous$$anager.ShieldUpgrade50.gameObject.SetActive(false);


Because an image is on a gameObject.


avatar image surfuay · Dec 11, 2018 at 01:52 AM 0
Share

will that method solve the location problem when I make it as a gameobject or the inactive to active problem when I make it as a UI image.

avatar image Vega4Life surfuay · Dec 11, 2018 at 02:43 AM 0
Share

This will fix your inactive/active problem.


I still feel you may be confused about a UI image and a gameObject. When you created the UI image, it creates a gameObject and puts an image component on it. Thus, anything in the scene is going to be a gameObject.

avatar image surfuay · Dec 11, 2018 at 03:05 AM 0
Share

ok, SO, you solved it. It didn't help that I'm new and a few things weren't clicking until you made you last point.

I didn't realize that even tho i made a UI Image it still counts as a game object, so in my script i was able to declare it as a game object and place the image inside that part of the editor.

when i first did "create empty" and made that the gameobject with the sprite i couldn't anchor on the same scales as the other UI elements which is what i really needed for consistency.

now that i know i can declare a game object in the script and a Ui Image in the canvas and place the image in the area for that gameobject it made it very easy to setactive to false or true.

you're awesome. would you $$anonymous$$d retyping your answer as an answer, it's not letting me reward you and this was super helpful.

avatar image Vega4Life surfuay · Dec 11, 2018 at 03:12 AM 0
Share

No problem. We all are learning. :)


Just as more knowledge, UI element is special in that it uses a rect transform ins$$anonymous$$d of a normal transform. All UI elements us this special transform. It has all the functionality as a transform (it derives from it), but it allows you to use anchors and such. Helps make sure everything is scaled properly in the UI canvas.

avatar image surfuay · Dec 11, 2018 at 03:13 AM 0
Share

any idea why when i build it to my android it doesn't function like it does in the editor?

avatar image Vega4Life surfuay · Dec 11, 2018 at 03:21 AM 0
Share

I would delete the app. $$anonymous$$ake sure everything is indeed updated in your scene. Then create another build. $$anonymous$$aybe the project didn't save or was in a weird state and didn't get your changes.

avatar image surfuay Vega4Life · Dec 11, 2018 at 03:58 AM 0
Share

will do you've been super helpful!

1 Reply

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

Answer by Vega4Life · Dec 11, 2018 at 03:09 AM

UI images live on gameObjects, so you can still SetActive on them. Like this:


 ShopUIManager.shopUIManager.ShieldUpgrade50.gameObject.SetActive(false);

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

114 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 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

OnSelect and OnPointerEnter work in one script but not another on the same object 2 Answers

Calling setActive(false) on a disabled object? 3 Answers

Turning off ONE GUI button 1 Answer

how to disable a button after pressing it and enable again after pressing another button 1 Answer

Re enable the script to recover the initial variables 2 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