Esempio n. 1
0
    void Update()
    {
        stamina = Mathf.Clamp(stamina, -1, maxStamina - x * 50);
        if (sprinting)
        {
            stamina -= m_ForwardAmount * fitness * Time.fixedDeltaTime;
        }
        else if (m_IsGrounded)
        {
            stamina += Time.fixedDeltaTime * 2;
        }

        if (stamina < 0)
        {
            tpHealth.ApplyDamage(Time.fixedDeltaTime / 6);
            staminaImage.fillAmount = 1;
            staminaImage.color      = Color.red;
        }
        else
        {
            staminaImage.color      = staminaBarCol;
            staminaImage.fillAmount = stamina / maxStamina;
        }
        if (Time.fixedTime >= nextAudibleCheck)
        {
            CheckAudibleDistance();
            audibleRange.localScale = new Vector3(audibleDistance, 0, audibleDistance);
            nextAudibleCheck        = Time.fixedTime + audibleCheckRate;
        }
    }
    public void OnCollisionEnter(Collision col)
    {
        if (col.rigidbody)
        {
            if (col.rigidbody.velocity.magnitude > 12f)
            {
                EnableRagdoll();
                tpHealth.ApplyDamage(Mathf.Clamp(col.rigidbody.velocity.magnitude, 0, 9));
                audiosource.PlayOneShot(hits[Random.Range(0, hits.Length)]);
            }
        }

        if (!tpMotor.m_IsGrounded && col.impulse.magnitude > 5f)
        {
            EnableRagdoll();
            tpHealth.ApplyDamage(Mathf.Clamp(col.impulse.magnitude, 0, 9));
            audiosource.PlayOneShot(hits[Random.Range(0, hits.Length)]);
        }
    }
    public void ApplyDamage(float damage)
    {
        float newDamage = damage * damageMultiplier;

        if (tpHealth)
        {
            tpHealth.ApplyDamage(newDamage);
        }
        if (tpObject)
        {
            tpObject.ApplyDamage(newDamage);
        }
    }