Hi everyone !
I am currently trying to change the sprite from the SpriteRenderer of an instantiated prefab to another after a collision.
I have attached a script to the prefab containing this :
public Sprite newSprite;
void OnTriggerEnter2D(Collider2D col) {
GetComponent().sprite = newSprite;
}
My prefab has a BoxCollider2D and a RigibBody2D, and I am sure that I go through this code thanks to Debug.Log.
Furthermore, when I print the sprite before and after on the console, it looks like the sprite has changed.
However, in game nothing happens... I think it's because I want to change the sprite of a clone and it's an issue but I'm not sure.
I have searched for a lot a answers but nothing helped me.
Thanks in advance and have a good day !
↧