Unity — changing material with enums

Let’s take our previous example a step further… Suppose we want to change the color of our ai to match the change in speed when we press the space bar, like this:

Since we’ve already set up our custom class, we can easily add a material to our enum:

Now we can add our materials using the inspector:

And with a few extra lines added to our Speed script:

We’ve done it!