I've been trying to use this function to trigger an sound when entering a trigger but i can't make it work. I've read and read my code and nothing seems off, looks exactly like the documentation says so i just can't figure out my error.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class footsteps_script : MonoBehaviour
{
public GameObject soundObject;
public GameObject trigger;
private AudioClip clip;
public bool nextTrig;
void Start()
{
nextTrig = false;
clip = soundObject.GetComponent<AudioClip>();
}
void OnTriggerEnter ()
{
if (Bunny_script.nextTrig == true)
{
soundObject.GetComponent<AudioSource>().PlayOneShot(clip);
nextTrig = true;
trigger.SetActive(false);
}
}
}
The AudioSource is atached to another object. The trigger is supposed to play the sound after another event happens. The trigger part works fine because nextTrig is set to true like intended, but the sound doesn't play. Also, the sound itself works fine too and with a nice volume.