예제 #1
0
    public void OnCollisionEnter(Collision other)
    {
        IZombie   zombie = other.collider.GetComponentInParent <IZombie> ();
        Rigidbody a      = other.collider.attachedRigidbody;

        if (zombie)
        {
            float x = 1;
            for (int i = 0; i < zombie.damageLevels.Length; i++)
            {
                if (other.collider == zombie.damageLevels[i])
                {
                    x = Mathf.Pow(i + 1, 2);
                }
            }
            zombie.ApplyPain((int)(damage * x + Random.Range(0, damage * x)));
            DropBlood(trans.position, trans.rotation);

            for (int i = 0; i < zombie.partsOfZ.Length; i++)
            {
                if (zombie.partsOfZ[i].coll == other.collider)
                {
                    zombie.partsOfZ [i].CatchOff();
                }
            }
            if (a)
            {
                zombie.lastDamageColl      = a;
                zombie.lastDamageDirection = -other.relativeVelocity * damage / 50;
            }
        }
        if (a)
        {
            a.velocity = -other.relativeVelocity * damage / 200f;
        }

        /*IHuman human = other.collider.GetComponentInParent<IHuman> ();
         *
         * if (human) {
         *      if (human.savable.name != "player") {
         *              float x = 1;
         *              for (int i = 0; i < human.damageLevels.Length; i++) {
         *                      if (other.collider == human.damageLevels[i]) {
         *                              x = Mathf.Pow(i + 1, 2);
         *                      }
         *              }
         *              human.savable.ApplyDamage ((int)(damage * x + Random.Range(0, damage * x)));
         *              DropBlood (trans.position, trans.rotation);
         *      }
         * }*/

        if (!other.collider.GetComponent <IBullet>())
        {
            float r = Random.Range(0f, 100f);
            if (r < 90)
            {
                Destroy(gameObject);
            }
        }
    }