First: I´m totally new with programming and this must be an easy task so I hope you can help me to fix this while I learn from your approximation to this so maybe I can solve future problems in my beginner project.
So I´m trying to make a gameobject to change its sprite when it collides with another one. In the code you can see that I made the CandleLit and CandleUnlit with public properties so I dragged the corresponding sprites to their respective slot in the Inspector in Unity... the idea is that when the CandleUnlit collider touches the collider of my object with tag "Smallfire" it switch the sprite of CandleUnlit to the sprite of CandleLit... I don´t have errors in console but nothing is happening when the collision occurs so I know it must be a very stupid problem whit the way I understand the scripting flow... so I hope someone can help me to find what i´m missing or what did I do wrong. Thanks in advance I will check my tutorials while waiting for someone´s help because I can´t figure it out after many hours by my self :(
public class CandleSpriteSwitch : MonoBehaviour
{
public Sprite CandleLit;
public Sprite CandleUnlit;
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "SmallFire")
{
gameObject.GetComponent<SpriteRenderer>().sprite = CandleLit;
}
else
{
gameObject.GetComponent<SpriteRenderer>().sprite = CandleUnlit;
}
}
}