private void OnCollisionEnter(Collision col) { if (ignoreGameObjects.Contains(col.transform.gameObject)) { return; } if (col.gameObject.layer == hitLayer) { EntityAI ai = col.gameObject.GetComponent <EntityAI> (); if (ai == null) { PlayerControls player = col.gameObject.GetComponent <PlayerControls> (); if (player == null) { Debug.Log("Invalid Object set to Entity Layer: " + col.gameObject.name); } player.TakeDamage(damage); } else { ai.DamageEntity(damage); } } DestroySelf(); }
private void DamageNearbyEntities() { Collider[] hits = Physics.OverlapSphere(transform.position, radius, entityLayer); for (int i = 0; i < hits.Length; i++) { EntityAI ai = hits[i].transform.GetComponent <EntityAI> (); if (ai == null) { PlayerControls player = hits[i].transform.GetComponent <PlayerControls> (); if (player == null) { Debug.LogError("Invalid Object on Entity layer: " + hits[i].transform.name); return; } player.TakeDamage(damage); return; } ai.DamageEntity(damage); } }