How can I change the color of the block being broken?

I’m curious as to how those breakable block sprites you have change to the color of the block being broken? I’m creating my own but I don’t want to have to do it for each set of sprites that I have.

Hello Mary,

I’ve not reviewed the updated version of this course content yet, so my suggestion may not be inline with the approach used in the course, but you could…

  • create your sprite and convert to grayscale for example
  • import your sprite into Unity and set its Texture Type to _Sprite (2D and UI)
  • create a new GameObject, name it “Red Block”
  • reset the Transform component to 0, 0 ,0
  • drag your sprite onto the Red Block GameObject
  • change the Color property of the Sprite Renderer component to red
  • drag the Red Block GameObject from the Hierarchy to the Assets folder to create a prefab
  • repeat the above process for the damaged blocks also

Now, with a selection of blocks in the hierarchy, e.g. a whole block, a partially damaged block, and a very damaged block perhaps, select all three and then set the Color property of the Sprite Renderer component to a different colour - perhaps green. Rename each GameObject accordingly. Drag all of the GameObjects into the Assets folder to create a set of prefabs for the new colour.

Repeat for each colour.

Alternatively…

You could do the above to only create the undamaged blocks, then, in your code which handles the blocks being damaged, swap the sprite that is being used to the damaged sprite. The Sprite Renderer component would still hold the colour that you had set and your damaged sprite would appear in this colour.

Note, if you colour the blocks in whatever software you are creating them in, you may find this clashes with the above process, hence suggesting you grayscale them, or perhaps just use white sprites - all depends on the detail of the sprite really.

Hope this helps, and as I say, the process in the course may be different to the above. :slight_smile:

Thank you!

1 Like

You’re very welcome Mary :slight_smile:

Hi I made all of my breakable blocks in grayscale. But I see that when the instructors blocks are put into the inspector he changes its color within the inspector only on the main block. The breakable sprite are automatically the same color as he chose. How is that happening?

1 Like

Oh nevermind I got it, lol!!!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms