void OnDestroy() { GameObject explosion = Instantiate(Exploding); explosion.transform.position = transform.position; explosion.transform.rotation = transform.rotation; CanCheckForEnemies = true; collisionPeriodElapsed = 0.0f; CameraShake shake = Camera.main.gameObject.GetComponent <CameraShake>(); if (shake != null) { shake.DoShake(); } if (CanCheckForEnemies) { GameObject[] objArr = GameObject.FindGameObjectsWithTag("Enemy"); //collisionPeriodElapsed += Time.deltaTime; //if (collisionPeriodElapsed < TotalCollisionPeriod) { for (int i = 0; i < objArr.Length; i++) { if (Vector3.Distance(objArr[i].transform.position, transform.position) < BlastRadius) { EnemyCollisionManager collisionManager = objArr[i].GetComponent <EnemyCollisionManager>(); if (collisionManager != null) { collisionManager.DestroyEnemy(); } } } //} objArr = GameObject.FindGameObjectsWithTag("Drone"); for (int i = 0; i < objArr.Length; i++) { if (Vector3.Distance(objArr[i].transform.position, transform.position) < BlastRadius) { DroneAI droneAI = objArr[i].GetComponent <DroneAI>(); if (droneAI != null) { droneAI.Damage(); } } } } }
void OnTriggerEnter2D(Collider2D collider) { // Prevent enemies from colliding with one another if (collider.gameObject.tag != "Enemy") { DestroyEnemy(); } if (gameObject.tag == "Enemy" && collider.gameObject.tag == "Friendly") { DestroyEnemy(); Destroy(collider.gameObject); } if (gameObject.tag == "Drone" && collider.gameObject.tag == "Laser") { DroneAI droneAI = gameObject.GetComponent <DroneAI>(); if (droneAI != null) { droneAI.Damage(); } } }