Beispiel #1
0
    public void OnGUI()
    {
        if (GUILayout.Button("Play Explosion"))
        {
            SoundKit.instance.playSound(explosion);
        }

        if (GUILayout.Button("Play Explosion via One Shot"))
        {
            SoundKit.instance.playOneShot(explosion);
        }

        GUILayout.Space(20);

        if (GUILayout.Button("Play Fart"))
        {
            SoundKit.instance.playSound(fart);
        }

        if (_loopedFartSound == null)
        {
            if (GUILayout.Button("Play Fart Looped"))
            {
                _loopedFartSound = SoundKit.instance.playSound(fart).setLoop(true);
            }
        }
        else
        {
            if (GUILayout.Button("Stop Looping Fart Sound"))
            {
                _loopedFartSound.stop();
                _loopedFartSound = null;
            }
        }

        if (GUILayout.Button("Play Fart with Completion Handler"))
        {
            SoundKit.instance.playSound(fart)
            .setCompletionHandler(() => Debug.Log("done playing fart"));
        }

        GUILayout.Space(20);

        if (GUILayout.Button("Play Rocket"))
        {
            SoundKit.instance.playSound(rocket);
        }

        if (GUILayout.Button("Play Squish"))
        {
            SoundKit.instance.playSound(squish);
        }

        if (GUILayout.Button("Play Wind Background Audio"))
        {
            SoundKit.instance.playBackgroundMusic(windBGSound, 8f, true);
        }

        if (GUILayout.Button("Stop Background Audio"))
        {
            SoundKit.instance.backgroundSound.stop();
        }

        if (GUILayout.Button("Toggle AudioListener.pause"))
        {
            AudioListener.pause = !AudioListener.pause;
        }


        GUILayout.Label("Sound Effect Volume");

        var oldVolume = _volume;

        _volume = GUILayout.HorizontalSlider(_volume, 0f, 1f);
        if (oldVolume != _volume)
        {
            SoundKit.instance.soundEffectVolume = _volume;
        }


        GUILayout.Space(20);
        if (SoundKit.instance.backgroundSound != null)
        {
            GUILayout.Label("BG Music Volume");

            oldVolume      = _bgMusicVolume;
            _bgMusicVolume = GUILayout.HorizontalSlider(_bgMusicVolume, 0f, 1f);
            if (oldVolume != _bgMusicVolume)
            {
                SoundKit.instance.backgroundSound.audioSource.volume = _bgMusicVolume;
            }
        }
    }
Beispiel #2
0
    void Update()
    {
        if (_controller.isGrounded)
        {
            _velocity.y = 0;
        }

        if (Input.GetButton(_buttons[Button.RIGHT]))
        {
            normalizedHorizontalSpeed = 1;
            if (transform.localScale.x < 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

            if (_controller.isGrounded)
            {
                _animator.Play(Animator.StringToHash("Run"));
            }
            if (!runs)
            {
                SoundK = SoundKit.instance.playSoundLooped(run);
                runs   = true;
            }
        }
        else if (Input.GetButton(_buttons[Button.LEFT]))
        {
            normalizedHorizontalSpeed = -1;
            if (transform.localScale.x > 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

            if (_controller.isGrounded)
            {
                _animator.Play(Animator.StringToHash("Run"));
            }
            if (!runs)
            {
                SoundK = SoundKit.instance.playSoundLooped(run);
                runs   = true;
            }
        }
        else
        {
            normalizedHorizontalSpeed = 0;

            if (_controller.isGrounded)
            {
                _animator.Play(Animator.StringToHash("Idle"));
            }
            if (runs)
            {
                runs = false;
                SoundK.stop();
            }
        }

        // move pickupObject
        if (isHolding)
        {
            pickedUpObject.transform.position = new Vector3(transform.position.x + (transform.localScale.x / 2), transform.position.y + 1, transform.position.z);;
        }

        // we can only jump whilst grounded
        if (_controller.isGrounded && Input.GetButtonDown(_buttons[Button.A]))
        {
            _velocity.y = Mathf.Sqrt(2f * jumpHeight * -gravity);
            _animator.Play(Animator.StringToHash("Jump"));
            SoundKit.instance.playOneShot(jump);
        }


        // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
        var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping;         // how fast do we change direction?

        _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor);

        // apply gravity before moving
        _velocity.y += gravity * Time.deltaTime;

        // if holding down bump up our movement amount and turn off one way platform detection for a frame.
        // this lets us jump down through one way platforms
        if (_controller.isGrounded && Input.GetButton(_buttons[Button.DOWN]))
        {
            _velocity.y *= 3f;
            _controller.ignoreOneWayPlatformsThisFrame = true;
        }

        _controller.move(_velocity * Time.deltaTime);

        // grab our current _velocity to use as a base for all calculations
        _velocity = _controller.velocity;

        if (Input.GetButtonDown(_buttons[Button.B]))
        {
            //TODO: b-button stuff!
            Debug.Log(_buttons[Button.B]);

            if (isHolding)
            {
                // if holding Throwable => Throw
                // calc force
                Vector2 force = new Vector2(transform.localScale.x * throwForce.x, throwForce.y);
                isHolding = false;
                pickedUpObject.Throw(force);
                pickedUpObject = null;
            }
            else
            {
                // if near Throwable => Pick up
                if (pickedUpObject != null)
                {
                    pickedUpObject.StartHolding();
                    isHolding = true;
                    // else => Punch
                }
                else
                {
                    // punch
                }
            }
        }
    }