public void StopIfPlaying()
 {
     if (handle != null)
     {
         handle.Stop();
     }
 }
        //
        IEnumerator ShockPlayer()
        {
            //This serves as the 'Is Coroutine Running' variable
            CurrentlyShocking = true;

            //This is a construct for our repetition of the traversal effect.
            float delay = .4f;

            //Prevent the loop/effect from running forever.
            int breakout = 0;

            //A handle for canceling the shock when the condition is no longer true.
            HapticHandle shockHandle = null;

            //This is the loop that will re-start the impulse
            //Remember that CurrentShocking is a bool from outside this function. Meaning it can be turned off and then we leave the loop.
            while (CurrentlyShocking && breakout < 25)
            {
                //Finally, don't forget to play the effect.
                shockHandle = shockImpulse.Play();

                //Wait before the next zap
                yield return(new WaitForSeconds(delay));

                //Max of X Zaps.
                breakout++;
            }

            //If we stop shocking the player, we want to clean up the last effect played. This means when the player stops touching the outlet, they stop getting shocked.
            shockHandle.Stop();

            //Mark that we aren't shocking the player.
            CurrentlyShocking = false;
        }
Beispiel #3
0
        private void ReleaseArrowHaptics()
        {
            if (HapticEffectWhenDrawAndReleased)
            {
                pulledHandle.Stop();

                if (pulled)
                {
                    pulled = false;
                    var impulse = ImpulseGenerator.BeginEmanatingEffect(WhichSide, 2);
                    impulse.WithEffect(hapticOnRelease).WithDuration(.25f).WithAttenuation(.8f);
                    impulse.Play();
                }
            }
            ResetPulledHaptic();
        }