private void searchForEnemies() { Collider2D[] col = Physics2D.OverlapCircleAll(transform.position, rangeRadius, enemyMask); Transform closest = null; float minDist = rangeRadius; foreach (Collider2D collider in col) { IHealthDamager hitable = collider.gameObject.GetComponent <IHealthDamager>(); if (hitable != null) { float dst = Vector2.Distance(collider.transform.position, transform.position); if (minDist > dst) { RaycastHit2D hit = Physics2D.Raycast(transform.position, (collider.transform.position - transform.position).normalized, dst, obsticleMasks); if (hit) { Debug.Log("hit"); if (hit.collider != collider) { Debug.Log(hit.collider.name); continue; } } minDist = dst; closest = collider.transform; } } } shooting.SetTarget(closest); }
private void OnCollisionEnter2D(Collision2D collider) { if (collider.gameObject.CompareTag("Enemy")) { IHealthDamager health = collider.gameObject.GetComponent <IHealthDamager>(); if (health != null) { health.TakeDamage(damage); StopAllCoroutines(); pocket.AddToPocket(new Costs(2)); } } Destroy(gameObject); }
private void CastExplosin() { Collider2D[] col = Physics2D.OverlapCircleAll(transform.position, range, enemyMask); foreach (Collider2D collider in col) { if (collider.CompareTag("Enemy")) { IHealthDamager hitable = collider.gameObject.GetComponent <IHealthDamager>(); if (hitable != null) { hitable.TakeDamage(new Damage(damage.HP, damage.Sheelds, gameObject)); } } } }
private void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.CompareTag("Player")) { IHealthDamager health = other.gameObject.GetComponent <IHealthDamager>(); if (isReadyToAttak && health != null) { health.TakeDamage(damage); isReadyToAttak = false; PlayerPocket.Pocket.AddToPocket(new Costs(2)); Audio.PlaySound("PlayerTakesDmg"); Destroy(gameObject); } } }