Graphics Reference
In-Depth Information
{
if(volume==volumeON)
fadeState=1;
} else {
if(volume==0)
fadeState=0;
}
A quick interpolation between the current volume and the targetVolume, with the
time it takes to fade decided by Time.deltaTime multiplied by fadeTime:
volume=Mathf.Lerp(volume, targetVolume,
Time.deltaTime * fadeTime);
source.volume=volume;
}
}
The last two functions in the MusicController class set up the fader variables for either
fading in or fading out through code. The single parameter fadeAmount is a value for
which to decide how long it should fade in or out:
public void FadeIn ( float fadeAmount )
{
volume=0;
fadeState=0;
targetFadeState=1;
targetVolume=volumeON;
fadeTime=fadeAmount;
}
public void FadeOut ( float fadeAmount )
{
volume=volumeON;
fadeState=1;
targetFadeState=0;
targetVolume=0;
fadeTime=fadeAmount;
}
}
8.3 Adding Sound to the Weapons
There are two places that may, at first glance, make good sound trigger points for weap-
ons. One is when the fire button is pressed in the player script, and the other is when the
projectile itself is created.
Making a sound when the fire button is pressed may seem like a good idea, but to do
that, we have to make sure that the projectile actually makes it into the world. After the
fire button is pressed, it may be that there is no ammunition left in the weapon or that the
weapon is in its reloading period. Making the sound without firing the projectile would
be rather silly.
Making a sound when the projectile is spawned may in fact be a better option, as it
will only make a sound when a projectile is successfully made. Also, the sound can be
Search WWH ::




Custom Search