//Fuction for checking Collision with another object. void OnCollisionEnter2D(Collision2D col) { //Checking if something has actually collided with attack if (col.collider != null) { //Checks if the tag of the object collided with is an Enemy Tag if (col.gameObject.CompareTag("Enemy")) { //Debug log for testing purposes Debug.Log("Collision has happened"); //Destroys the attack after colision happens Destroy(attackPrefab.gameObject); // REF_EnemyController enemy = col.collider.GetComponent <REF_EnemyController>(); if (enemy != null) { Vector2 KnockbackDir = rb2d_Attack.transform.forward; enemy.rb2d_Enemy.velocity = KnockbackDir * 5; enemy.DamageEnemy(0); } } } }
private void OnCollisionEnter2D(Collision2D col) { if (col != null) { if (Attacking == true) { if (col.gameObject.CompareTag("Enemy")) { REF_EnemyController enemy = col.collider.GetComponent <REF_EnemyController>(); if (enemy != null) { enemy.rb2d_Enemy.velocity = KnockbackDir - enemy.rb2d_Enemy.position; enemy.DamageEnemy(0); } } Debug.Log("Attack Collision has happned"); Attacking = false; } } }