private void HandleAudio(Vector3 newPos) { // A gentle bit of audio feedback for // swishing back and forth Vector3 moved = newPos - lastPos; float distance = moved.magnitude; bool createEffect = (distance > distanceSpeedForFx); if (mopEffect) { mopEffect.SetMode(createEffect); } float elapsed = Time.time - measureTime; if (elapsed >= timeForDistance) { if (distance >= measureDistance) { if (!audioLooper.Playing) { audioLooper.Play(); } // Temp stop if changing direction if (Vector3.Dot(moved, lastDirection) < 0) { //Debug.Log("DIRECTION CHANGE"); if (audioLooper.Playing) { audioLooper.Stop(); } } } else if (audioLooper.Playing) { if (mopEffect) { mopEffect.SetMode(false); } audioLooper.Stop(); } measureTime = Time.time; lastDirection = moved; lastPos = newPos; } }
public override void OnInspectorGUI() { DrawDefaultInspector(); AudioLooper alScript = (AudioLooper)target; if (GUILayout.Button("Play")) { alScript.Play(); } else if (GUILayout.Button("Playthrough")) { alScript.PlayThrough(); } else if (GUILayout.Button("Fadeout")) { alScript.Fadeout(); } }