浏览代码

Allow for randomized audio on boat collisions

/2019.3-marc
Marc Tanenbaum 5 年前
当前提交
f9fef69a
共有 2 个文件被更改,包括 42 次插入0 次删除
  1. 31
      Assets/Scripts/Boat/BoatAudioCollision.cs
  2. 11
      Assets/Scripts/Boat/BoatAudioCollision.cs.meta

31
Assets/Scripts/Boat/BoatAudioCollision.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class BoatAudioCollision : MonoBehaviour
{
public AudioClip[] audioClips;
public float variability = .5f;
private AudioSource audioSource;
private void Start()
{
audioSource = gameObject.GetComponent<AudioSource>();
}
void OnCollisionEnter(Collision col)
{
if(col.gameObject.layer == gameObject.layer)
{
int c = Random.Range(0, audioClips.Length-1);
AudioClip clip = audioClips[c];
audioSource.clip = clip;
audioSource.pitch = 1 + Random.Range(-variability, variability);
audioSource.Play();
}
}
}

11
Assets/Scripts/Boat/BoatAudioCollision.cs.meta


fileFormatVersion: 2
guid: 627e3b520aaa746738d844a971a1e0ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存