Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 MounirDev · Jul 24, 2019 at 09:02 PM · unity 2dimagedecreasefill

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.

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
1

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);
 }
 }



Comment
Add comment · Show 2 · 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 MounirDev · Jul 24, 2019 at 09:29 PM 0
Share

@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!

avatar image MounirDev · Jul 24, 2019 at 11:05 PM 0
Share

i've found the problem ! "amount" is actually a negative value lool so i just have to write : maskblue.fillAmount += value;

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

112 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 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 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 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

Image is normal in scene view but in game view it looks pixelated. 0 Answers

Update one-colored rectangle with circle shaped holes once per second. 0 Answers

Create a bar that has 4 colours in it 1 Answer

I have an image of a circle with black boundary and it is filled with white colour. Now i want to fill white portion with red colour by mouse click. 2 Answers

I want to fill a circle with red colour. There is a boundary of black colour and the other region is of white colour. 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