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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
3
Question by lampshade · Aug 27, 2010 at 08:05 PM · guiprogress-barcircular

Fill a Circular Progress Bar Based on Value

alt textHi,

Edit: I need to fill up a circle texture with another texture (apparently a material) based on a value. I have two Texture varaibles, 'rightCircle' and 'backgroundTexture'. I have a material texture 'mat' of which is a transparant/cutout/diffuse shader. alt text public Texture backgroundTexture, rightCircle; public Material mat;

void OnGUI() { if (Event.current.type == EventType.Repaint) { mat.SetFloat("_Cutoff", Mathf.InverseLerp(0, 48, someScript.growVar);

     Graphics.DrawTexture(new Rect(987, 0, 58, 45), backgroundTexture, mat);
     Graphics.DrawTexture(new Rect(987, 0, 58, 45), rightCircle);
 }

}

EDIT -- The above draws a square (alpha) with the image of a circle in the middle of the square. [o] <-- kind of like that, but with the top and bottom width's drawn in. Each time that someScript.growVar increments, a little portion of the square dissapears...but instead of the square (alpha) being drawn, I need it to be a circle.. :-/

Comment
Add comment · Show 7
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 matyicsapo · Aug 29, 2010 at 06:11 AM 1
Share

rightCircle is just to show a border for the circle, right? (try removing it for now); the materials mainTexture..try meddling with that; edit you post to include an image of atleast what you see as that "[0]" is pretty fuzzy atleastforme8-)

avatar image lampshade · Aug 29, 2010 at 06:35 AM 0
Share

I agree, How can I upload a pic? I'm also getting run time errors for the Graphics.DrawTexture() function has mat as one of its paramaters.

avatar image lampshade · Aug 29, 2010 at 06:47 AM 0
Share

http://yfrog.com/5bmyimagep

avatar image matyicsapo · Aug 29, 2010 at 06:48 AM 0
Share

the errors could help too

avatar image matyicsapo · Aug 29, 2010 at 07:00 AM 1
Share

thought it would be simple; I'd comment out lines till it's working again, DrawTexture()s, Event stuff, someScript referencing or meddle with the mat; sry can't seem to help more :/

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by matyicsapo · Aug 27, 2010 at 09:15 PM

have you tried looking around? maybe this related question might help? http://answers.unity3d.com/questions/7449/creating-a-circular-progressbar-timer the alpha texture idea is i guess what you need too

create a material, set it's shader to transparent cutout and prolly diffuse, for the main texture use a texture use sg. like the one in the above link where white parts represent fully opaque, or as mine alt text

if you go with a textured object, a plane for example use sg. like the following code from Update() prolly

renderer.material.SetFloat("_Cutoff", alphaCutoff);

but I assume you wanna stick to GUI so you could do sg. like this:

void OnGUI () {
    if (Event.current.type == EventType.Repaint) {
        mat.SetFloat("_Cutoff", alphaCutoff);
        Graphics.DrawTexture(screenRect, texture, mat);
    }
}

check out the documentation for Graphics.DrawTexture() - the reason for the event fuss

in both cases the alphaCutoff is the float value you'll alter based on your (game)logic

(using the above pic for the alpha texture I have some bugs and artifacts(not the one that it's upside-down))

Comment
Add comment · Show 5 · 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 lampshade · Aug 27, 2010 at 09:20 PM 0
Share

Thanks for the reply, I have seen that post, but I have idea how to implement it into the above code! The documentation has a varaiable defined as "paramater" which to me suggests that the inv. lerp function goes in as the width?

avatar image lampshade · Aug 27, 2010 at 09:43 PM 0
Share

I need to reference the renderer.material.SetFloat() via a texture to get it to work probably...

avatar image matyicsapo · Aug 27, 2010 at 10:27 PM 1
Share

..you wanna fill up a circle with a texture based on a value? draw the circle and then the filling texture with it's alpha so it doesn't go out of the circle..might have misunderstood you somewhere sry

avatar image lampshade · Aug 28, 2010 at 10:29 PM 0
Share

I used your code which you were so kind to provide, but I am not seeing the background texture being drawn within the circle..It is still a square shape fill. --Edited post

avatar image Draco18s · Sep 01, 2011 at 08:39 PM 0
Share

I'm having an issue where the texture when drawn to the screen (using the DrawTexture method) is appearing as all black and not as its correct color (green). The material I'm using has the texture render when placed on a plane in the world, but not when drawn with a GUIscript.

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

1 Person is following this question.

avatar image

Related Questions

Creating a Circular Progressbar / Timer 6 Answers

GUI Progress ? 2 Answers

Circular Progress Bar/Meter - how to generate smooth alpha channel for cutout? 1 Answer

How to make a progress bar(non uniform shape) 2 Answers

Creating a Lifebar with simple GUI in C# 3 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