ERROR CS0119 C# GetComponent< >
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 :)
Answer by JedBeryll · May 14, 2016 at 08:11 AM
GetComponent<Image>().color
You need a parenthesis after GetComponent
Your answer
Follow this Question
Related Questions
Changing image color from other object's script (glitch)? 0 Answers
error CS0119 What's wrong? (I have old asset maybe it helps you) 1 Answer
Using GetComponent without knowing the script name? 1 Answer
C# - Cannnot access variable in another script unless I get the component everytime. 1 Answer
How to fix "no overload for method get component takes 1 arguments" 1 Answer