RegionAudioTriggerAction - jimdroberts/FishMMO GitHub Wiki
RegionAudioTriggerAction is a region action ScriptableObject that triggers an audio clip for the player character when invoked. It is used within the FishMMO infrastructure to play a specific audio cue when a player enters or interacts with a region, enhancing immersion and feedback.
-
public AudioClip clip
The audio clip to play when the region action is triggered.
-
public override void Invoke(IPlayerCharacter character, Region region, bool isReconciling)
Invokes the region action, playing the specified audio clip for the player character if conditions are met.
-
character
(IPlayerCharacter): The player character to play the audio for. -
region
(Region): The region in which the action is triggered. -
isReconciling
(bool): Indicates if the action is part of a reconciliation process. This method does not return a value. No exceptions are thrown by this method.
-
- Ensure an AudioClip asset is available in your project.
- Create a new RegionAudioTriggerAction ScriptableObject via the Unity Editor (Assets > Create > FishMMO > Region > Region Audio).
- Assign the desired AudioClip to the
clip
field in the Inspector. - Attach the RegionAudioTriggerAction to a region definition or trigger in your game.
// Example 1: Assigning and using RegionAudioTriggerAction
// 1. Create a RegionAudioTriggerAction asset in the Unity Editor.
// 2. Assign an AudioClip to the 'clip' field in the Inspector.
// 3. Reference the asset in your region setup.
// Example usage in code:
regionAudioTriggerAction.Invoke(playerCharacter, region, false);
- Always assign a valid AudioClip to avoid null reference issues.
- Ensure only the owner of the network object triggers the audio to prevent duplicate playback.
- Avoid triggering audio during reconciliation to maintain correct game state.