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 /
avatar image
0
Question by soydasmemet · Feb 05, 2017 at 06:34 AM · androidplayersliderdamageenemies

Changing the Slider.value cause a lag problem in an Android device.

Hello,

I have a script for setting the enemies health when taking damage from a bullet. Its one method below in the code section, updates the health. It works well in unity editor. But in an android device, when the m_slider.value reaches the half value of the m_StartingHealth, it will cause a lag about 1-2 second for every colliding bullet. I can not figure out why, but that is just because of the "m_Slider.value = m_CurrentHealth" line. If i comment that part, it will work well. You can see the slider and filling images properities from the attachment. I will be pleased if you can help.

m_StartingHealth = 100.0f,

 private void SetHealthUI ()
     {
         // Set the slider's value appropriately.
         m_Slider.value = m_CurrentHealth;
     
         m_FillImage.color = Color.Lerp (m_ZeroHealthColor, m_FullHealthColor, m_CurrentHealth / m_StartingHealth);
     }
slideer.png (28.3 kB)
fill.png (29.0 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by oStaiko · Feb 05, 2017 at 03:58 PM

I did something like this on Android once but never encountered any lag with it before, try changing it to the code I used and see if it helps? Instead of a slider, I used a rectangular UI image, with image type set to filled -> horizontal -> and left. This creates the exact same effect as the slider, just without the little knob in the middle.

 if (health == healthMax || health <= 0)
 {
     img.color = new Color(0,0,0,0); //Hide hp bar
 }
 else
 {
     img.color = new Color ((healthMax-health)/(healthMax*.925f) + .075f, -(healthMax-health)/healthMax + 1, 0, 1);
     img.fillAmount = health/healthMax;
 }
Comment
Add comment · Show 3 · 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 soydasmemet · Feb 05, 2017 at 04:19 PM 0
Share

Actually i saw my way at this tutorial

I tried also rectangular UI like u said, but i try to create circular health bar as the tutorial above, for that purpose the filling image should be Radial 360. This problem occurs when it is radial. With the horizontal and vertical filling method, i did not encounter with this problem, too.

avatar image oStaiko soydasmemet · Feb 06, 2017 at 12:16 AM 0
Share

The initial question says that you wanted a slider which is a horizontal fill, but your comment says you want a radial fill? Can you explain more on what you want and why this doesn't work?

avatar image soydasmemet oStaiko · Feb 06, 2017 at 07:48 AM 0
Share

No, i did not asked about horizontal fill :) $$anonymous$$aybe i could not explain the details well, you can see the filling image properties from the attachments, its radial and i want a circular health bar with radial fill exactly like the tutorial at my first comment.

I tried something. When i set the fill origin as "left","right" or "bottom" ins$$anonymous$$d of "top", the problem never occured. So, i don't use the "top" option. This is the solution for me, for now :)

I think, i didn't miss anything. The problem is "top" option. It is interesting and might be a bug? or i can't see the logic behind of it. If you can see, please let me know.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Dungeon Enemy Help 1 Answer

Does no damage. 1 Answer

Why does Video Player render black on Android with Multithreading Off? 0 Answers

how do i kill multiple enemies? 0 Answers

How do I make my player re-spawn in its original place on collision of enemy? 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