private void OnTriggerEnter2D(Collider2D other) { HealthCollider hc = other.GetComponent <HealthCollider>(); if (hc != null) { float dist = CalculateDistToCollider(other); Target t = new Target(); t.HealthObj = hc.HealthObj; t.Collider = other; t.Dist = dist; t.PrevPos = hc.HealthObj.transform.position; TargetsInRange.Add(t); TargetsInRange.OrderBy(x => x.Dist); } }
void OnTriggerEnter(Collider col) { if (dangerous && col.gameObject.layer == 8 && col.tag == "HealthCollider") // 8 layer is Unit { HealthCollider h = col.GetComponent <HealthCollider>(); if (h.masterHealth.health > 0) { bloodSplatterEmission.rate = 500; StartCoroutine("DisableBlood"); } if (!h.masterHealth.invisible && h.masterHealth.health > 0) { au.pitch = Random.Range(0.75f, 1.25f); au.PlayOneShot(attackClips[Random.Range(0, attackClips.Count)]); h.Damage(damage + Random.Range(-damage / 4, damage / 4), weaponAmmoType); } } }
private void DoDamage(Collider2D col) { bool bDestroy = false; HealthCollider healthCol = col.GetComponent <HealthCollider>(); HealthComponent health = healthCol == null ? null : healthCol.HealthObj; if (health != null && health.Side != Side) { health.Health -= Amount; bDestroy = DestroyOnDamage; } else { bDestroy = DestroyOnCollision; } if (bDestroy) { Destroy(RootObject == null ? gameObject : RootObject); } }