Click audio feedback

For the audio, find an audio clip you'd like to use when something is clicked. We include one named FingerPressed with our chapter Assets package. Rather than adding it with an AudioSource to every button and clickable object, we'll centralize the sound and add it to the GameController, along with a PlayClickFeedback() function:

  1. Select the GameController in Hierarchy and Add Component Audio Source.
  2. Find your audio clip, such as at Assets/SimpleIcons/Sounds/FingerPressed, and drag it into the AudioClip slot on the Audio Source component.
  3. Uncheck Play On Awake.
  4. Leave the Spatial Blend at 2D so it's not affected by the user's head position.

Now edit the GameController script:

File: GameController.cs
private AudioSource clickSound; void Start() { clickSound = GetComponent<AudioSource>(); } public void PlayClickFeedback() { if (clickSound != null) { clickSound.Play(); } }

We can now add the following line of code to the OnInputClicked method in both the PictureAction and ClickableObject scripts:

        GameController.instance.PlayClickFeedback(); 

When you press Play and click on something, you should hear the feedback.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset