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 haruhi4 · Jul 21, 2016 at 05:11 PM · assetasset storebarprogress bar

Position of bars using Gradient GUI Bars asset from asset store

Hi, i am currently using this Gradient GUI Bars on my Unity project: (https://www.assetstore.unity3d.com/en/#!/content/19972)

They're really helpful, but there's a problem with them: Since the position of the bar is done using an attribute called "public Vector2 Position;" (from the GUIBarScript script that is attached to all my bars i use in the game), when my game is on fullscreen mode, the bars are at a different position from when my game is not fullscreen. Then, I have tried to make the class not use the Position attribute at all(i have changed the whole GUIBarScript class to use transform.localposition instead of this "Position" attribute). Instead, use the transform.localposition. Still, it seems like the Vector2 Position works differently from a normal localposition. My question is: How can I make the GUIBarScript do not use Position and use the object's current position instead? And how different is this Vector2 Position compared to the natural transform.position from the gameObject on Unity.

Sorry for posting this question here on the forum, but the creator of the asset doesn't read his email, i guess so I can't seem to have an option to contact him

Comment
Add comment · Show 1
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 haruhi4 · Jul 21, 2016 at 05:26 PM 0
Share

It seems like the creation of a Rect uses position coordinates that are different from GameObject's transform coordinates and that is the problem. So, how do i create a rect using a gameobjects position? $$anonymous$$aybe that will solve my problem

1 Reply

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

Answer by TBruce · Jul 23, 2016 at 10:40 PM

The problem is that this asset was made with an older version of Unity (4.5.4) which does not have support anchoring objects to the screen. The asset needs to be updated to use the new Unity UI.

I have attached a Unity package. There is one scene that has a UI prefab. I took the original GUIBarScript.cs and modified it to use the UI instead of the GUI. The new script is called UIBarScript.cs.

The UIBarScript script to is attached a canvas called GradientBar. To change the anchor select the Background UI GameObject.

It uses the artwork and font from the GradientGUIBars\Bars\DriveStyle folder. If you wish to use different artwork then you will need to import it (images will need to be sprites not textures).

Good luck and enjoy.

UIGradient


uigradient.zip (41.3 kB)
Comment
Add comment · Show 11 · 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 haruhi4 · Jul 25, 2016 at 01:50 PM 0
Share

Thank you so much, @$$anonymous$$avina ! This looks like the correct solution! I will work right away to modify my project and check the results. Just something i wanted to ask: If i wanted to put the rect on a position that's not x=0 and y=0, what should i do? I have tried to modify the UpdateBar() function: when you create int x = 0;and int y = 0;, ins$$anonymous$$d of 0 i put the value of public attributes i defined, but it seems to me the bar isn't moving to any position. Is there any way to use those coordinates i have when i use a normal gameObject(you know, the ones that are in the gameObject's transform component)?

avatar image TBruce haruhi4 · Jul 25, 2016 at 03:03 PM 0
Share

The proper way to use this is to first set your anchor of the Background GameObject (see Anchor presets and Anchor and position fields in the Inspector on this page).

Then set the position of the Background GameObject to the desired location using either the RectTransform PosX and PosY or in the scene view using the position tool. Watching the Game View you can see where the UI bar will stay no matter what resolution.

Note: Per above, there is no need to modify the code. Just set the anchor and position visually the way you want. Also the GameObject GradientBar in the scene is a Canvas and must remain at the root in the scene.

avatar image TBruce haruhi4 · Jul 25, 2016 at 03:36 PM 0
Share

Here is a short video showing how to set the position with anchors.

Note: When setting your anchor, it is easier if you hold the ALT key at the same time.

avatar image haruhi4 TBruce · Jul 25, 2016 at 06:16 PM 0
Share

Thank you for the help @$$anonymous$$avina and Sorry for the work, but how do i scale the bar in this solution? I have noticed that the GradientBar is a component i can't scale and the background, mask, value bar... they are several different components that if i scale them individually, the bar stops working(like, the value bar keeps on 10% even though the value isn't)

Show more comments
avatar image haruhi4 · Jul 25, 2016 at 08:38 PM 0
Share

@$$anonymous$$avina, ins$$anonymous$$d of position, i used alpha. Now, the only problem I'm facing is that i want to draw the bar right beside(on the right of) a certain GameObject. On fullscreen and on no fullscreen, the bar needs to be right beside the gameObject. Is there any way to do that on Unity? I have tried to use this user's answer to my other topic: http://answers.unity3d.com/questions/1219518/drawing-a-rectangle-on-gameobjects-position.html but still didn't work.

avatar image TBruce haruhi4 · Jul 25, 2016 at 09:35 PM 0
Share

I do not know what you mean when you say ins$$anonymous$$d of position, i used alpha.

alpha relates to the color of an object not the position.

What is this GameObject that you need to place the bar next to? If it is a sprite that is easy.

Here is a little demo showing you how.

avatar image haruhi4 TBruce · Jul 26, 2016 at 03:09 PM 0
Share

@$$anonymous$$avina Thank you so much for all your answers, $$anonymous$$avina. You really saved me and now everything is working with my Bar! Thanks to your last answer, the bar is now on the same height as a gameobject and on the correct position on all screen sizes. Thank you so much! ^^

Oh, by the way, "ins$$anonymous$$d of position i used alpha" means that i wanted all the components from a screen to disappear in order to another group of components from another screen appear. Normally, i would move all the objects to a position the user can't see, but now i'm using alpha with the GuiBar, because it's better than moving it to another position.

Thank you ^^

Show more comments

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

62 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

Related Questions

How to include Standard Assets in a custom asset? (best practices?) 0 Answers

i cant down load any new assets I have purchased from untiy asset store 0 Answers

Aset store download issue 0 Answers

If I will buy asset is this one time purchase or monthly subscribe? 1 Answer

What should I do? 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