Audio Playing for Different Objects On Trigger
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TriggerAudio : MonoBehaviour {
public AudioClip audioPlay;
AudioSource audioSrc;
bool alreadyPlayed = false;
// Use this for initialization
void Start () {
audioSrc = GetComponent<AudioSource> ();
}
void OnTriggerEnter()
{
if (!alreadyPlayed) {
audioSrc.PlayOneShot (audioPlay);
alreadyPlayed = true;
}
}
}
using System.Collections.Generic;
using UnityEngine;
public class TriggerAudio : MonoBehaviour {
public AudioClip audioPlay;
AudioSource audioSrc;
bool alreadyPlayed = false;
// Use this for initialization
void Start () {
audioSrc = GetComponent<AudioSource> ();
}
void OnTriggerEnter()
{
if (!alreadyPlayed) {
audioSrc.PlayOneShot (audioPlay);
alreadyPlayed = true;
}
}
}
Comments
Post a Comment