Ejemplo n.º 1
0
    public void TakeDamage(float damage, ContactPoint hitPoint = new ContactPoint(), Vector3 hitDirection = new Vector3())
    {
        _health -= damage;
        _health  = _health < 0 ? 0 : _health;

        lastHit = new DamageHit(hitPoint.point, hitDirection);

        if (_character.isPlayer)
        {
            UIController.instance.UpdateHealthUI(_health);
        }
    }
    public virtual void ReceiveDamage(DamageHit hit)
    {
        if (!isActive)
        {
            return;
        }

        damageFlagInternal       = true;
        hit.overrideDamageAmount = OnDamage(hit);

        DamageHit = hit;

        Hp -= hit.overrideDamageAmount;
    }
Ejemplo n.º 3
0
    //Detects if the punch caused damaged with gameobject and direction
    void PushHit(GameObject hit, Vector3 point)
    {
        DamageHit dmgHit = hit.GetComponentInChildren <DamageHit>();

        if (dmgHit == null)
        {
            return;
        }

        float myDamage = dmgHit.calculateDamage(damage);

        dmgHit.GetHit(myDamage, point);

        if (damageFont != null)
        {
            GameObject txt = GameObject.Instantiate(damageFont, point, Quaternion.identity) as GameObject;
            txt.GetComponent <TextMesh>().text = myDamage.ToString();
        }
    }
Ejemplo n.º 4
0
    public void HitRagdoll(DamageHit hitPoint, float power)
    {
        Vector3 dir             = hitPoint.dir;
        Vector3 origin          = hitPoint.point - dir;
        Vector3 impulseVelocity = dir * power;

        RaycastHit hit;
        //raycast character and targets
        int layerMaskCharacter = 1 << 8;
        int layerMaskTarget    = 1 << 9;
        int finalMask          = layerMaskCharacter | layerMaskTarget;

        Debug.DrawLine(origin, origin + dir * 2, Color.green);
        if (Physics.Raycast(origin, dir, out hit, Mathf.Infinity, finalMask))
        {
            hit.rigidbody.AddForceAtPosition(impulseVelocity, hit.point, ForceMode.Impulse);
        }
        else
        {
            characterSpine.attachedRigidbody.AddForce(impulseVelocity, ForceMode.Impulse);
        }
    }
 protected virtual float OnDamage(DamageHit hit)
 {
     return(hit.damageAmount);
 }