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 Notter · Mar 27, 2015 at 01:21 PM · uigraphicsbarmeter

What's the best way to draw lines on a meter bar

I need to make a bar that looks like this:

alt text

I've already got the bar working with a slider behind a mask, and made a panel on the right that generates the numbers (they need to by created dynamically)

all that's left is creating the lines inside the meter. they need to be created dynamically (prefab) and be able to change color.

i'm fairly new to unity, so i thought maybe someone can suggest a nice way to do this

lines.jpg (11.8 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

1 Reply

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

Answer by sumeeton · Mar 27, 2015 at 02:49 PM

If you want different colors for different box, the slider texture won't work. From what I see, you need a step meter and not a smooth sliding meter. You'll need a white box as texture. Use that as prefab. Recode to instantiate boxes according to the values and change the color of the prefab using color property.

Comment
Add comment · Show 4 · 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 Notter · Mar 27, 2015 at 08:40 PM 0
Share

Hmm, sorry i guess it wasn't clear enough from the picture. i don't want a "Step meter", the meter can have values between the lines.

avatar image sumeeton · Mar 28, 2015 at 04:37 AM 0
Share

Considering you are using Unity UI for this meter, follow these steps: 1) Use an UI Image for drawing the lines. You need not apply a texture to the image. Simply change it's color. 2) Create its prefab after setting the size and anchor. You'll need to instantiate and make it child to a gameobject that has the slider gameobject as a child. This is so because you need to have both of these masked and you don't want the lines to be moved with the slider.

 line.transform.SetParent(sliderContainer.transform);

3) Position the line where you want. You'll need to Z-order or sorting layers to render lines above the slider. Apply the settings to your prefab and slider. 4) To change the color, simply use:

 using UnityEngine.UI;
 
 Image lineImage = line.GetComponent<Image>();
 lineImage.color = new Color32(r, g, b, a); // your rgb values here

5) To achieve tweening effect while changing colors of the lines, you'll need to use Coroutine or Update and then scale the rgb values and achieve the effect.

avatar image Notter · Mar 28, 2015 at 06:33 PM 0
Share

Thank you for the in-depth answer :) I have already in fact managed something almost exactly similar to what you've instructed, but my question was "what's the best way to do it", and you've confirmed that i had the correct idea. so thanks agian!

avatar image sumeeton · Mar 28, 2015 at 07:12 PM 1
Share

Trust your instincts!

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

How to access another sprite's texture from a 2D shader 0 Answers

Updating UI Slider through another script 1 Answer

Is it possible to import maya mental ray light effects in unity without using baking?? 2 Answers

How do you create an animated texture for a UV'd Mesh and apply it? 1 Answer

Drawing several cubes produces graphical glitches. 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