- Home /
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);
}
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;
}
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.
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?
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.