how do I add to the rgb value in the sprite renderer?

Hi,

This is the bit of code i have so far… I know i’ve made a mistake somewhere . My desired result is to have the object flash before its destroyed.

.this.GetComponent<SpriteRenderer>.color = + .15f, + .15f, + .15f, 1f;

Thanks in advance for any help.

try this

this.GetComponent<SpriteRenderer>.color = new Color(.15f, .15f, .15f, 1f);
1 Like

that didn’t do the trick, it just changes the bricks to a different color. (almost black) I need it to make the object appear to flash and then either go back to normal or get destroyed.

void OnCollisionEnter2D (Collision2D collision)    {
    AudioSource.PlayClipAtPoint(crack, transform.position, 0.2f);
        this.GetComponent<SpriteRenderer>().color = new Color(+ .15f, + .15f, + .15f, 1f);
    if (isBreakable) {
        HandleHits();
        }

}

    void HandleHits () {
       
        timesHit ++;
        int maxHits = hitSprites.Length + 1;
        if (timesHit >= maxHits){
            breakableCount--;
            levelManager.BrickDestroyed();
            PuffSmoke();
            Destroy(gameObject);

            print(breakableCount + " Blocks Left");
        }
        else {
            LoadSprites();
        }
    }

Heres more of the code in case it helps…

Have you tried that?

public Color myColor = new Color();

Then on the inspector you can choose your color.
And then you add this on your OnCollisionEnter2D script.

this.GetComponent<SpriteRenderer>().color = myColor;
1 Like

If you intend add to the current color, you need to do something like this:

        Color c = GetComponent<SpriteRenderer>().color;
        c.r += .15f;
        c.g += .15f;
        c.b += .15f;
        GetComponent<SpriteRenderer>().color = c;
1 Like

this worked beautifully… thank you so much. Also thanks to everyone that posted. I appreciate the help.