Game Development Reference
In-Depth Information
will play the Sound variable we created on Line 1. You can specify which
AudioClip in the code, but we'll do it an easier way.
Line 4:
Don't forget to close the curly braces to end the function:
}
Save this function in MonoDevelop by going to File > Save or by using
the keyboard shortcut Command+S/Ctrl+S. Then close the editor. The
text for the function should appear in the Inspector View and the script
will be compiled. Any errors found in the script will appear in red at the
bottom of the window or in the Console.
Apply the Script to the Intended Object
Now that we have a script done, what we can do is drag the script over
the object that we want to use it on in the Hierarchy. First, i nd your
script, and drag it over the Door object in the Hierarchy.
Look at the Door object in the inspector. Notice that it now has a
Component with the name of the script that you just created added to it.
You should also notice that there is a variable called Sound indicated on
the script which should show “ None (AudioClip) ”.
Click the small round button to the right edge to browse for ImpactDoor.
wav or choose your own sound. You can also simply drag any audio clip
from the project over this area, but be careful not to release the mouse
button inside the Project View, or the Inspector View will change.
 
Search WWH ::




Custom Search