New to FMOD.
I have a trigger, which the player walks through to enter a different room, it’s a prefab and I’ve got several of this same prefab throughout the game.
I want to play a unique audio clip when the player passes through each door, but I would like to avoid creating a new script for every door.
I’ve had a look online and I can’t find/understand how to go about implementing what I want.
My Door Trigger
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
public class RoomTrigger : MonoBehaviour
{
[SerializeField] private Vector2 camMinChange;
[SerializeField] private Vector2 camMaxChange;
[SerializeField] private Vector3 playerChange;
[SerializeField] CameraFollow camFollow;
private void Start()
{
camFollow = Camera.main.GetComponent<CameraFollow>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "Player")
{
TransitionRoom(collision);
AudioManager.instance.PlayOneShot(FMODEvents.instance.useDoorSound, this.transform.position);
}
}
private void TransitionRoom(Collider2D collision)
{
camFollow.minPos += camMinChange;
camFollow.maxPos += camMaxChange;
collision.transform.position += playerChange;
}
}
My Audio Manager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMODUnity;
public class AudioManager : MonoBehaviour
{
public static AudioManager instance { get; private set; }
private void Awake()
{
if(instance != null)
{
Debug.Log("there is more than one Audio Manager");
}
instance = this;
}
public void PlayOneShot(EventReference sound, Vector3 worldPos)
{
RuntimeManager.PlayOneShot(sound, worldPos);
}
}
Storing all my sounds in this FMOD Events script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMODUnity;
public class FMODEvents : MonoBehaviour
{
[field: Header("Narration")]
[field: SerializeField] public EventReference Narration00 { get; private set; }
[field: SerializeField] public EventReference Narration111 { get; private set; }
[field: Header("Room SFX")]
[field: SerializeField] public EventReference useDoorSound { get; private set; }
public static FMODEvents instance { get; private set; }
// ensures there is only one of these in scene
private void Awake()
{
if(instance != null)
{
Debug.Log("Too many 'FMOD Events' in here");
}
instance = this;
}
}