Пример #1
0
    private void EmitFootsteps()
    {
        if (_inputMovement != Vector3.zero && _notGroundedTimer <= 2)
        {
            int    soundfreq = 13;
            string soundName = "Step";
            float  soundSize = 0.5f;
            if ((Input.GetButton("Sneak") || Input.GetAxisRaw("Sneak") != 0))
            {
                soundfreq = 20;
                soundName = "StepM";
                soundSize = 0;
            }
            else if (Input.GetButton("Run"))
            {
                soundfreq = 10;
                soundName = "StepR";
                soundSize = 1;
            }

            if (Time.frameCount % soundfreq == 0)
            {
                _snd.Play(soundName);
                _emitter.EmitAudio(transform.position, soundSize);
            }
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        //on throw
        if (!collision.gameObject.CompareTag("Player"))
        {
            if (State == PickupItemState.Normal && _isThrown)
            {
                if (_destructable && DamageTimer <= 0)
                {
                    //do damage
                    DamageTimer = _damageTime;
                    Health--;
                    _snd.Play("Break");
                    //Debug.Log(_rb.velocity.magnitude);
                }
                _audioEmitter.EmitAudio(collision.contacts[0].point, _rb.velocity.magnitude);

                if (collision.gameObject.CompareTag("Enemy"))
                {
                    Enemy enemy = collision.gameObject.GetComponent <Enemy>();
                    enemy.Damage(1, transform.position);
                    _rb.AddForce((transform.position - collision.transform.position).normalized * _enemyBounceoffForce, ForceMode.Impulse);
                }
            }
            _snd.Play("Hit");
            _isThrown = false;
        }
    }