void Start()
    {
        poof       = SoundM.CreateSoundInstance("Poof");
        transition = SoundM.CreateSoundInstance("Transition");

        InvokeRepeating("decreaseMissCounter", 2, 6);
    }
Example #2
0
    void Start()
    {
        trainMetronome = SoundM.CreateSoundInstance("TrainMetronome", transform, GetComponent <Rigidbody>());
        rhythm         = SoundM.CreateSoundInstance("Forest", transform, GetComponent <Rigidbody>());

        SoundM.PlaySound(trainMetronome);
        SoundM.PlaySound(rhythm);
        SoundM.SetSoundParameter("TrackVolume", 1);
    }
    void musicSoundStuff(string button, int mode) // 0 - just check    1 - change
    {
        if (mode == 1)
        {
            if (button == "music")
            {
                if (music)
                {
                    GameObject.Find(button).GetComponent <Image>().sprite = off;
                }
                else
                {
                    GameObject.Find(button).GetComponent <Image>().sprite = on;
                }
                music = !music;

                SoundM.EnableMusic(music);
            }
            if (button == "sound")
            {
                if (sound)
                {
                    GameObject.Find(button).GetComponent <Image>().sprite = off;
                }
                else
                {
                    GameObject.Find(button).GetComponent <Image>().sprite = on;
                }
                sound = !sound;

                SoundM.EnableSound(sound);
            }
        }
        else
        {
            if (music)
            {
                GameObject.Find("music").GetComponent <Image>().sprite = on;
            }
            else
            {
                GameObject.Find("music").GetComponent <Image>().sprite = off;
            }

            if (sound)
            {
                GameObject.Find("sound").GetComponent <Image>().sprite = on;
            }
            else
            {
                GameObject.Find("sound").GetComponent <Image>().sprite = off;
            }
        }
    }
Example #4
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Example #5
0
    void Start()
    {
        if (GenerateObjects == true)
        {
            GameObject createCache = new GameObject();
            createCache.name = "Audio_Effects";
            createCache.AddComponent <AudioSource>();
            createCache      = new GameObject();
            createCache.name = "Audio_Music";
            createCache.AddComponent <AudioSource>();
        }

        //Find Objects
        GameObject cache = GameObject.Find("Audio_Effects");

        if (cache != null)
        {
            Effects = cache.GetComponent <AudioSource>();
        }

        cache = GameObject.Find("Audio_Music");
        if (cache != null)
        {
            Music = cache.GetComponent <AudioSource>();
        }

        //Set Instance
        instance = this;

        //Start Music and end Initphase
        if (Effects != null && Music != null)
        {
            if (MusicEnabled == true)
            {
                //Play Background Muisc
                Music.clip = BackgroundMusic;
                Music.loop = true;
                Music.Play();
            }

            Init = true;
        }
    }
    public void Hit(int hand)
    {
        if (audioManager.checkBeatHit(hand))
        {
            if (streakCounter == 0)
            {
                streakTimer = streakLength;
            }

            SoundM.PlaySound(poof, handObject[hand].transform.position);
            streakCounter++;
            //Debug.Log("hit streak: " + streakCounter);

            handObject[hand].GetComponentInChildren <ParticleSystem>().Play();
        }

        /*else if (!audioManager.checkBeatHit(hand))
         * {
         *  streakCounter == 0;
         * }*/
    }
Example #7
0
    void Update()
    {
        transform.position = player.transform.position;

        SoundM.SetSoundParameter("Speed", audioSpeed);
        SoundM.SetSoundParameter("RhythmIndex", (float)rhythmIndex);

        int newTimelinePos;

        rhythm.getTimelinePosition(out newTimelinePos);

        /*fmodTimeDelta += (float)(newTimelinePos - timelinePosition) / 1000;
         * timeDelta += Time.deltaTime;
         * if (fmodTimeDelta < 0)
         * {
         *  timeDelta = 0;
         *  fmodTimeDelta = 0;
         * }
         * if (fmodTimeDelta > 2)
         * {
         *
         *  //Debug.Log(timeDelta + " , " + fmodTimeDelta);
         *
         *  realSpeed = (realSpeed + timeDelta / fmodTimeDelta) /2;
         *  timeDelta = 0;
         *  fmodTimeDelta = 0;
         *  Debug.Log(realSpeed);
         * }*/

        beatTimeout -= (int)(Time.deltaTime * 1000);
        beatTimeout  = Mathf.Max(beatTimeout, 0);

        float newTime       = Mathf.Repeat((float)newTimelinePos / 1000, 4);
        float newOffsetTime = Mathf.Repeat((float)newTimelinePos / 1000 + (noteDelay /** realSpeed*/), 4);


        if (leftHandRhythms[rhythmIndex] != "" && rightHandRhythms[rhythmIndex] != "")
        {
            //parse list from string
            string[] lhArray = leftHandRhythms[rhythmIndex].Split(',');
            string[] rhArray = rightHandRhythms[rhythmIndex].Split(',');

            float lhNextBeat = Mathf.Repeat(float.Parse(lhArray[lhIndex % lhArray.Length]), 4);
            float rhNextBeat = Mathf.Repeat(float.Parse(rhArray[rhIndex % rhArray.Length]), 4);

            //releasing beat puffs
            if (beatTimeout == 0)
            {
                if (newOffsetTime >= lhNextBeat && newOffsetTime <= lhNextBeat + 0.1)
                {
                    beatTimeout = 100;

                    //play release steam puff
                    emitLeft();
                    lhIndex++;
                }

                if (newOffsetTime >= rhNextBeat && newOffsetTime <= rhNextBeat + 0.1)
                {
                    beatTimeout = 100;

                    //play release steam puff
                    emitRight();
                    rhIndex++;
                }
            }

            /*if (Input.GetButtonDown("Fire1"))
             * {
             *  if (checkBeatHit(0))
             *  {
             *      //Debug.Log("Hit Left Beat");
             *  }
             *  else
             *  {
             *      //Debug.Log("Missed Left Beat");
             *  }
             * }*/

            //check which beats are in range to be hit by left hand
            for (int i = 0; i < lhArray.Length; i++)
            {
                float beat = Mathf.Repeat(float.Parse(lhArray[i]), 4);

                if (Mathf.Abs(newTime - beat) < beatTolerance ||
                    (newTime < beatTolerance && beat >= 4 - beatTolerance) ||
                    (newTime > 4 - beatTolerance && beat <= beatTolerance))
                {
                    if (beat != currentLeftBeat)
                    {
                        //new beat
                        currentLeftBeat = beat;
                    }
                }
                else
                {
                    //no beat
                    if (beat == currentLeftBeat)
                    {
                        //check if player has hit the current beat
                        if (leftBeatIgnore != currentLeftBeat)
                        {
                            //leftBeatIgnore = currentLeftBeat;
                            Debug.Log("Missed Beat, Time: " + newTime);
                            playerManager.consecutiveMisses++;
                        }

                        currentLeftBeat = -1;
                    }
                }
            }

            //check which beats are in range to be hit by right hand
            for (int i = 0; i < rhArray.Length; i++)
            {
                float beat = Mathf.Repeat(float.Parse(rhArray[i]), 4);

                if (Mathf.Abs(newTime - beat) < beatTolerance ||
                    (newTime < beatTolerance && beat >= 4 - beatTolerance) ||
                    (newTime > 4 - beatTolerance && beat <= beatTolerance))
                {
                    if (beat != currentRightBeat)
                    {
                        //new beat
                        currentRightBeat = beat;
                    }
                }
                else
                {
                    //no beat
                    if (beat == currentRightBeat)
                    {
                        //check if player has hit the current beat
                        if (rightBeatIgnore != currentRightBeat)
                        {
                            //rightBeatIgnore = currentRightBeat;
                            Debug.Log("Missed Beat, Time: " + newTime);
                            playerManager.consecutiveMisses++;
                        }

                        currentRightBeat = -1;
                    }
                }
            }
        }

        timelinePosition = newTimelinePos;


        //adjust focus parameter
        SoundM.SetSoundParameter("Focus", playerManager.focus);
    }
    // Update is called once per frame
    void Update()
    {
        Vector3 handVel;
        Vector3 handAngVel;

        for (int hand = 0; hand < handObject.Length; hand++)
        {
            handObject[hand].GetComponent <Hand>().GetEstimatedPeakVelocities(out handVel, out handAngVel);
            if (handVel.magnitude > 1f)
            {
                handObject[hand].GetComponent <Collider>().enabled = true;
            }
            else
            {
                handObject[hand].GetComponent <Collider>().enabled = false;
            }
        }

        if (consecutiveMisses > missAllowance)
        {
            //reset streak timer and counters
            consecutiveMisses = 0;
            streakCounter     = 0;

            streakTimer = -1;
        }

        if (streakTimer > 0)
        {
            streakTimer -= Time.deltaTime;
        }
        else if (streakTimer != -1)
        {
            if (audioManager.rhythmIndex < audioManager.rightHandRhythms.Count - 1)
            {
                audioManager.rhythmIndex++;
                streakTimer     = -1;
                streakCounter   = 0;
                transitionTimer = transitionTimerLength;

                SoundM.PlaySound(transition, transform.position);
            }
        }

        SoundM.UpdateSoundPos(transition, transform.position);

        //increase focus based on streak timer
        if (streakTimer >= 0 && consecutiveMisses == 0)
        {
            focus = Mathf.Clamp(1 / streakLength * (streakLength - streakTimer) * 1.5f, 0, 1);
        }
        else
        {
            focus = 0;
        }

        if (transitionTimer > 0)
        {
            transitionTimer -= Time.deltaTime;
        }
        else
        {
            transitionTimer = 0;
        }

        if (transitionTimer > 0)
        {
            //during transition make steam invisible
            steamAlpha += (0 - steamAlpha) * 0.01f;
        }
        else
        {
            //adjust steam alpha based of level of focus
            steamAlpha += (Mathf.Clamp(0.2f - (Mathf.Max(focus - 0.6f, 0) * 2), 0f, 1) - steamAlpha) * 0.01f;
        }
        trainSteamController.steamAlpha = steamAlpha;

        if (Input.GetButtonDown("Fire1"))
        {
            fallbackLeftHand.SetActive(true);
            //Hit(0);

            Invoke("DisableFallbackHands", 0.2f);
        }

        if (Input.GetButtonDown("Fire2"))
        {
            fallbackRightHand.SetActive(true);
            //Hit(1);

            Invoke("DisableFallbackHands", 0.2f);
        }
    }
 public void ClickOnButton()
 {
     SoundM.PlaySound(0);
     tab.OpenTab(this.name);
 }