So I have a door that Activates once the Player Enters Its Collider.
I only need the sound to play once but I am terrible with Scripting.
After the door is already opened the Player can collide with it and it will play the sound again,
as i intend it to only play once.
Ive Tried Changing _audioSource.Play(); to _audioSource.PlayOneShot(); but it doesnt seem to work. I have also
watched numerous tutorials and looked at other peoples questions but they all seem to be
extremely specific and dont match with my problem.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorScript : MonoBehaviour
{
private Animator _animator;
private AudioSource _audioSource;
private void Awake()
{
_animator = GetComponent<Animator>();
_audioSource = GetComponent<AudioSource>();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
_animator.SetBool("open", true);
_audioSource.Play();
}
}
}