Hi, so i am trying to change the sprite of the child object to do some sort of “damage” visualization but when i try to access the spriterenderer from script it does nothing.
I made an array of sprites and thought it would be pretty easy to change the sprite when i’d want it to change but it doesn’t work, this is my code
(PS: i already tried the getComponentInChildren but it didn’t work so i tried to go directly by putting the gameobject i wanted the sprite renderer to change, to debug)
SpriteRenderer SpriteChildRenderer;
float maxHealth;
float HealthState;
[SerializeField] GameObject children;
[SerializeField] Sprite[] canSprites;
private void Start()
{
SpriteChildRenderer = children.GetComponent<SpriteRenderer>();
Integrity = 1;
health= GetComponent<Health>();
maxHealth = health.GetHealth();
HealthState = maxHealth;
}
private void Update()
{
CheckState();
}
it is nothing special it’s quite simple, all it does are some check but idk
this is where i check for the state i want the sprite to change
private void CheckState()
{
HealthState= health.GetHealth();
if (0.7f >= (HealthState / maxHealth))
{
Integrity = 0;
SpriteChildRenderer.sprite = canSprites[Integrity];
}
if (0.5f >= (HealthState / maxHealth))
{
Integrity = 1;
SpriteChildRenderer.sprite = canSprites[Integrity];
}
if (0.2f >= (HealthState / maxHealth))
{
Integrity = 2;
SpriteChildRenderer.sprite = canSprites[Integrity];
}
i’m trying to simply change the sprite from this
to this
but it does nothing, even if i try to change the sprite on START ,