CLONING COLORS QUEST - Magic Gem

Here is my solution:

public class MagicGem : MonoBehaviour
{
    private SpriteRenderer spriteRenderer;

    private void Awake()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Block"))
        {
            SpriteRenderer playerSpriteRenderer = collision.GetComponent<SpriteRenderer>();
            if(playerSpriteRenderer != null )
            {
                playerSpriteRenderer.color = this.spriteRenderer.color;
            }
        }
    }
}

I’m loving this course :smiley:

Privacy & Terms