private void Update() { if (gameObject.activeInHierarchy) { RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.up, range, layermask); damageTimer -= Time.deltaTime; if (hitInfo.collider != null) { if (damageTimer <= 0) { Debug.Log("Hit"); if (hitInfo.collider.GetComponent <Npc>()) { Npc enemyhit = hitInfo.collider.GetComponent <Npc>(); enemyhit.ApplyDamage(damage); } damageTimer = damageDelay; } } } }