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

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