Game Development Reference
In-Depth Information
see the results of the effects that we used in our game. The image on the left shows
the Hard shadows and the image on the right shows the shadows turned off.
Now that you've seen the resulting effects of our shadow options, let's code these
options. Add this function to your script:
public void ToggleShadows(int newToggle)
{
Light[] lights =
GameObject.FindObjectsOfType<Light>();
foreach(Light light in lights)
{
if(newToggle == 0)
light.shadows = LightShadows.None;
else
light.shadows = LightShadows.Hard;
}
}
This function takes an int value, which will be used to toggle the shadows on or off.
Inside the function, we first grab all of the lights within the scene and assign them
to an array. Then, for each of the lights, we toggle their shadow's value to None or
Hard . This is how we turn the shadows on or off.
Search WWH ::




Custom Search