示例#1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        BombActivator bombAc = player.GetComponent <BombActivator>();
        Animator      anim   = GetComponent <Animator>();

        if (bombAc.nearBomb())
        {
            anim.SetBool("Near Bomb", true);
            if (Input.GetMouseButtonDown(0))
            {
                anim.SetTrigger("Click");
            }
        }
        else
        {
            anim.SetBool("Near Bomb", false);
        }
    }
示例#2
0
    void FixedUpdate()
    {
        if (playAudio)
        {
            bool          jumping = !GetComponent <RigidbodyFPSController> ().onGround;
            bool          moving  = Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f;
            BombActivator bombAc  = player.GetComponent <BombActivator> ();


            //If in jump by pressing jump key
            if (Input.GetKeyDown(KeyCode.Space) && !inJump)
            {
                jumpingSource.Play();
                runningSource.Stop();
                inJump    = true;
                startTime = Time.time;
            }

            //If jumped more than 0.1 sec ago
            if (inJump && jumping && Time.time - startTime > 0.1f)
            {
                playLand = true;
            }

            //If injump and landed
            if (inJump && !jumping && Time.time - startTime > 0.1f)
            {
                if (playLand)
                {
                    landingSource.Play();
                }
                inJump   = false;
                playLand = false;
            }

            //If standing on the ground - not moving and not inJump
            if (moving && !inJump && !jumping && !runningSource.isPlaying)
            {
                runningSource.Play();
                pantingSource.Stop();
            }

            //if jumping and moving stop running
            if (moving && jumping)
            {
                runningSource.Stop();
            }

            //If standing on the ground - not moving and not inJump
            if (!moving && !inJump && !pantingSource.isPlaying)
            {
                pantingSource.Play();
                runningSource.Stop();
            }

            //If near bomb
            if (bombAc.nearBomb())
            {
                if (Input.GetMouseButtonDown(0))
                {
                    beepsource.Play();
                    explosionsource.Play();
                }
            }

            //if faster than 14units
            if (player.GetComponent <RigidbodyFPSController>().currentSpeed > 18f)
            {
                float volume = (Time.time - whooshTime);
                if (volume < 1f)
                {
                    audiosourceDic[whooshSource] = volume;
                    changeVolume();
                }
                if (!whooshSource.isPlaying)
                {
                    whooshTime = Time.time;
                    whooshSource.Play();
                }
                playWhoosh = true;
            }
            else
            {
                /*(if(playWhoosh){
                 *      playWhoosh = false;
                 *      whooshTime = Time.time;
                 * }
                 * float volume = 1f-(Time.time - whooshTime);
                 * if(volume>0.1f){
                 *      audiosourceDic[whooshSource] = volume;
                 *      changeVolume();
                 * }
                 * else
                 *      whooshSource.Stop ();
                 * Debug.Log(volume); */

                whooshSource.Stop();
            }

            if (!musicSource.isPlaying)
            {
                playlistIndex++;
                if (playlistIndex == musicPlaylist.Count)
                {
                    playlistIndex = 0;
                    Shuffle(musicPlaylist);
                }
                musicSource.clip = musicPlaylist[playlistIndex];
                musicSource.Play();
                Debug.Log("playing " + musicPlaylist [playlistIndex].ToString());
            }
        }
    }