Add various sound effects
This commit is contained in:
30
Assets/Scripts/CollisionSound.cs
Normal file
30
Assets/Scripts/CollisionSound.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
|
||||
public class CollisionSound : MonoBehaviour
|
||||
{
|
||||
|
||||
public AudioSource audioSource;
|
||||
public AudioClip[] collisionSounds;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
this.audioSource.clip = this.collisionSounds[Random.Range(0, this.collisionSounds.Length)];
|
||||
this.audioSource.Play();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user