Skip to content

Commit 8b6bc9a

Browse files
authored
Create Sound_on_Trigger
1 parent 08b8326 commit 8b6bc9a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Sound_on_Trigger

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
4+
public class Sound_on_Trigger : MonoBehaviour {
5+
6+
public AudioClip SoundToPlay;
7+
public float Volume;
8+
AudioSource audio;
9+
public bool alreadyPlayed = false;
10+
void Start()
11+
{
12+
audio = GetComponent<AudioSource>();
13+
}
14+
15+
void OnTriggerEnter()
16+
{
17+
if (!alreadyPlayed)
18+
{
19+
audio.PlayOneShot(SoundToPlay, Volume);
20+
alreadyPlayed = true;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)