private void DoAttack() { if (DEBUG) { Debug.Log("Doing attack"); } foreach (Collider other in hitbox.GetColliding()) { if (DEBUG) { Debug.Log("Found entity in collider"); } if (other.gameObject.GetComponent <MeleeAIEnemy>()) { if (DEBUG) { Debug.Log("enemy taking damage"); } MeleeAIEnemy enemyAI = other.gameObject.GetComponent <MeleeAIEnemy>(); Vector3 knockbackDir = (enemyAI.transform.position - this.transform.position).normalized; Debug.Log(knockbackDir.y); enemyAI.TakeDamage(PLAYER_DAMAGE, HIT_STRENGTH * knockbackDir); } } }
//This gets called before Update functions. private void OnTriggerStay(Collider other) { if (other.gameObject.GetComponent <MeleeAIEnemy>() && Time.time > nextAttackTime) { //Attack enemy AI MeleeAIEnemy enemyAI = other.gameObject.GetComponent <MeleeAIEnemy>(); nextAttackTime = Time.time + Random.Range(0.5f, 1.0f); //nextAttackTime = Time.time + 0.5f; Vector3 temp = enemyAI.transform.position - this.transform.position; Vector3 knockbackDir = (new Vector3(temp.x, 0.0f, temp.z)).normalized; enemyAI.TakeDamage(1, HIT_STRENGTH * knockbackDir); } }