Hi everyone!
I’m totally novice in scripting but I found a script on internet which worked out, but for me it doesn’t! The error is “expression denotes a ‘type’ where a variable ‘value’ or ‘method group’ was expected”. In fact, the issue is about the GetComponent< Image > thing, but I don’t know by what I could replace it…
This is my script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class HealthBar : MonoBehaviour {
#region Attributes
public GameObject healthBar;
public Color goodColor;
public Color middleColor;
public Color badColor;
#endregion
#region Unity methods
void Stars()
{
SetColor();
}
#endregion
#region Other methods
public void SetDamages(float value)
{
healthBar.GetComponent<Scrollbar>().size -= value;
float totalValue = healthBar.GetComponent<Scrollbar>().size;
SetColor(totalValue);
}
void SetColor(float value = 1)
{
if(value >= 0.5f)
{
healthBar.transform.FindChild("Mask").FindChild("Sprite").GetComponent<Image>.color = goodColor;
}
else if(value >= 0.25f && value < 0.5f)
{
healthBar.transform.FindChild("Mask").FindChild("Sprite").GetComponent<Image>.color = middleColor;
}
else
{
healthBar.transform.FindChild("Mask").FindChild("Sprite").GetComponent<Image>.color = badColor;
}
}
#endregion
}
It would be really nice if some of you could help me