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 OctoMan · Nov 09, 2015 at 09:18 AM · calculatefillamount

Calculate Radial Fillamount

alt textI want to "clamp" the filled amount of an image with 360° radial like this:

I have:

 float max_amount = 500f;
 float cur_amount = max_amount;
 float minValue = 0.1f;
 float maxValue = 0.35f;

cur_amount needs to be calculated to fit a radial circle segment fill from 0.1f(minValue) to 0.35f(maxValue).

How can i calculate the fillamount? Normally i do this for the 360° complete circle.

 float calc_amount = cur_amount/max_amount;


radialfill.png (110.3 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

2 Replies

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

Answer by say_forever · Nov 09, 2015 at 09:41 AM

Hi, I am not sure whether my answer is what you want

 using System.Collections;
 using UnityEngine.UI;
 
 public class test : MonoBehaviour {
 
     float min_amount = 0.1f;
     float max_amount = 0.35f;
     float calc_amount;
     Image image;
     public float input;
 
 
     // Update is called once per frame
     void Update () {
 
 
         if (input <= max_amount && input > min_amount)
             calc_amount = (input - min_amount) / (max_amount - min_amount);
 
         image = gameObject.GetComponent<Image>();
         image.fillAmount = calc_amount;
 
     }
 }



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 OctoMan · Nov 09, 2015 at 09:58 AM 0
Share

Sadly this doesn't work, because 0.35f fillamount needs to be 100%.

When i decrease my currentvalue(cur_amount) it didn't moved before i reach 0.35f. So somehow i need to recalculate the max fill amount.

avatar image say_forever OctoMan · Nov 09, 2015 at 10:27 AM 0
Share

I updated the code and it work successfully.

avatar image OctoMan · Nov 09, 2015 at 10:32 AM 0
Share

What is input? I uploaded an image just in case i might be unclear. Gonna check your code again.

Edit: It seems my question is unclear. I gonna rework my question.

avatar image say_forever OctoMan · Nov 09, 2015 at 12:16 PM 0
Share

calc_amount = cur_amount % (maxValue - $$anonymous$$Value) + $$anonymous$$Value is what you want?

avatar image OctoMan say_forever · Nov 09, 2015 at 12:46 PM 0
Share

Your idea was almost right! I needed to make sure that calc_amount somehow fits into the (maxValue - $$anonymous$$Value)

 float calc_amount = cur_amount/max_amount;
 
 calc_output = calc_amount*(maxValue-$$anonymous$$Value) % (maxValue - $$anonymous$$Value) + $$anonymous$$Value;
 
 Healthbar.fillAmount = calc_output;

Now i just need to cap calc_amount to 0.

Thanks alot :)

avatar image
1

Answer by Paulo-maia · Jun 18, 2016 at 03:37 AM

@OctoMan your code was a great help thank you

//Otimized!!

Healthbar.fillAmount = (cur_amount/max_amount)*(maxValue - minValue)+minValue;

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

33 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

Related Questions

How could i create a fill bar which increase with a key press or decrease in function of time? 0 Answers

Why is my value of a variable playerpref always the same? 1 Answer

Progress bar (i.e. Health, Mana, etc...) filling up gradually... 1 Answer

Trajectory line throwing downward 0 Answers

Image.fillAmount not updating GUI,Image.fillAmount not updating on GUI - values get updated correctly 0 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