void OnTriggerStay(Collider col) { Vector3 colPos = col.gameObject.transform.position; Debug.Log("Collision with " + col.gameObject.name); if (colPos.y < 1.2) { myOsc.PlaySound(0); } else if (colPos.y < 1.4) { myOsc.PlaySound(1); } else if (colPos.y < 1.6) { myOsc.PlaySound(2); } else if (colPos.y < 1.8) { myOsc.PlaySound(3); } else if (colPos.y < 2) { myOsc.PlaySound(4); } mySynthControl.SetVolume(Mathf.Lerp(-80f, 0f, colPos.z)); mySynthControl.SetCutoff(Mathf.Lerp(100f, 15000f, colPos.x)); PlayParticles(); }
void SetVolume(Collider col, SynthControl sc) { Vector3 colPos = col.gameObject.transform.position; //determine where collider is within the box from float distFromBack = colPos.z - back; float localPosZ = distFromBack / gameObject.transform.localScale.z; float clampedLocalPosZ = Mathf.Clamp(localPosZ, 0, 1f); // ease out value with Sin, so it gets louder earlier when increasing local Z position float t = Mathf.Sin(clampedLocalPosZ * Mathf.PI * 0.5f); sc.SetVolume(Mathf.SmoothStep(-80f, 0f, t)); }