Calculate Radial Fillamount
I 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;
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;
}
}
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.
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.
calc_amount = cur_amount % (maxValue - $$anonymous$$Value) + $$anonymous$$Value is what you want?
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 :)
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;