- Home /
image.fillamount doesnt decrease
hi, i'm using the fill amount to change the health bar state, the value of decreasing depends on the weapon, i store the damage value in a variable called "value" and from another script i do this :
public void SetValue(float value)
{
maskblue.fillAmount -= value;
}
the fill amount doesn't change and stay 1, but if i change " value" by a float number ( 1f, 0.5f ) it works ! notice that in the other script i call the previous function "SetValue" like this :
public void ChangeHealth( float amount )
{
currentHealth += amount;
HealthBar.instance.SetValue(amount);
}
where the value of " amount" depends on the weapon's bullet ( -0.1 , -0.2 ...) i only did the -0.1 for no so.. I hope someone can help me! thank you.
Answer by I_Am_Err00r · Jul 24, 2019 at 09:10 PM
How are you referencing this health bar script in the weapon script? It doesn't look like the SetValue() function is getting the (float value) amount from that weapon script if it works when you manually enter the value.
An example would look something like this
public class Damage : Monobehaviour
{
HealthBarClass healthBar;
public void Start()
{
healthBar = GameObject.FindObjectOfType<HealthBarClass>();
}
public void Damage()
{
damage = weapon.Damage;
healthBar.SetValue(damage);
}
}
@I_Am_Err00r i'll try to write exactly what i did : 1) in the BulletTrigger script, when the bullet triggers the Ship i call ChangeHealth() from ShipDamage script :
void OnTriggerEnter2D(Collider2D other)
{
//usual code
ShipDamage ship = other.gameObject.GetComponent<ShipDamage>();
ship.ChangeHealth(-0.1f);
Destroy(gameObject);
}
now in the ShipDamage script, the ChangeHealth() looks like this :
public void ChangeHealth(float amount)
{
currentHealth += amount;
HealthBar.instance.SetValue(amount);
}
this will decrease currentHealth by 0.1f, this used to work so far. in a third script, HealthBar i have this :
public void SetValue(float value)
{
maskblue.fillAmount -= value;
}
the fill amount doesnt change at all!
i've found the problem ! "amount" is actually a negative value lool so i just have to write : maskblue.fillAmount += value;
Your answer
Follow this Question
Related Questions
how to instantiate images ui in different position randomly 0 Answers
How to change the end of image with type "Filled" 1 Answer
Image Fill Bug 0 Answers
Image custom fillOrigin 1 Answer
Fill an image with multiple colors? 2 Answers