public void CheckCollisions(WheelHit coll) { if (coll.collider.transform.GetComponent <TerrainType>()) { TerrainType terr = coll.collider.transform.GetComponent <TerrainType>(); if (makeBumpSounds) { //if (coll.force > (requiredForceForSmallBump + additionalForceRequiredForBigBump)) { // PlayBigBump(); // Debug.Log("BUMP"); //} //else { // if (coll.force > requiredForceForSmallBump) { // PlaySmallBump(); // Debug.Log("bump"); // } //} float verticalDisplacement = this.transform.position.y - previousVerticalPosition; float newVerticalVelocity = verticalDisplacement / Time.deltaTime; if (newVerticalVelocity - previousVerticalVelocity > requiredVelocityChangeForSmallBump + additionalVelocityChangeRequiredForBigBump) { PlayBigBump(); Debug.Log("BUMP"); } else { if (newVerticalVelocity - previousVerticalVelocity > requiredVelocityChangeForSmallBump) { PlaySmallBump(); Debug.Log("bump"); } } previousVerticalPosition = this.transform.position.y; previousVerticalVelocity = newVerticalVelocity; } if (currentlyPlayingContinuousSound) { if (terr.SurfaceType != currentGroundSurface) { PlayContinuousSound(terr.SurfaceType); } } else { if (terr.SurfaceType == currentGroundSurface) { PlayContinuousSound(terr.SurfaceType); currentlyPlayingContinuousSound = true; } } currentGroundSurface = terr.SurfaceType; } }
public void PlayContinuousSound(TerrainType.TypeOfSurface terrain) { AudioClip clip = null; if (continuousSoundsChannel) { switch (terrain) { case TerrainType.TypeOfSurface.Synthetic: clip = PickRandomSoundFromList(syntheticSounds); break; case TerrainType.TypeOfSurface.Grass: clip = PickRandomSoundFromList(glassSounds); break; case TerrainType.TypeOfSurface.Gravel: clip = PickRandomSoundFromList(gravelSounds); break; case TerrainType.TypeOfSurface.Metal: clip = PickRandomSoundFromList(metalSounds); break; case TerrainType.TypeOfSurface.Wood: clip = PickRandomSoundFromList(woodSounds); break; case TerrainType.TypeOfSurface.Glass: clip = PickRandomSoundFromList(glassSounds); break; case TerrainType.TypeOfSurface.Concrete: clip = PickRandomSoundFromList(concreteSounds); break; case TerrainType.TypeOfSurface.Fabric: clip = PickRandomSoundFromList(fabricSounds); break; } } if (clip) { continuousSoundsChannel.clip = clip; continuousSoundsChannel.Play(); } else { if (syntheticSounds.Count > 0) { continuousSoundsChannel.clip = syntheticSounds[Random.Range(0, syntheticSounds.Count)]; continuousSoundsChannel.Play(); } } }
// Start is called before the first frame update void Start() { col = this.GetComponent <WheelCollider>(); currentGroundSurface = TerrainType.TypeOfSurface.Synthetic; continuousSoundsChannel.loop = true; continuousSoundsChannel.volume = 0; previousVerticalPosition = 0; previousVerticalVelocity = 0; }