RegionAudioTriggerAction - jimdroberts/FishMMO GitHub Wiki

Description

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.


API Access

Fields

  • public AudioClip clip

    The audio clip to play when the region action is triggered.

Methods

  • 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.

Basic Usage

Setup

  1. Ensure an AudioClip asset is available in your project.
  2. Create a new RegionAudioTriggerAction ScriptableObject via the Unity Editor (Assets > Create > FishMMO > Region > Region Audio).
  3. Assign the desired AudioClip to the clip field in the Inspector.
  4. Attach the RegionAudioTriggerAction to a region definition or trigger in your game.

Example

// 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);

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️