It may be that the game designer has set the alpha value of a GameObject in the Inspector window to the initial value they want. So, let's enhance our code to allow this to be indicated by checking a public Boolean flag variable in the Inspector window and adding code to read and use the GameObject's alpha if that option is chosen.
Do the following:
- In the Inspector window, click Color picker for the Albedo material and set the Alpha value to something other than 255 (for example, set it to 32, which is almost transparent):
Figure 5.21 – Setting Rendering Mode of a material to Fade
- Add a new public Boolean variable to our script (default to false):
public bool useMaterialAlpha = false;
- Add logic to the Start() method so that if this flag is true, we use the Alpha value of the color that was read from...