//use delegate to parameterise the method: can take any method matching the signatures & argument, call it through delegate private void MoveEnemy(TextOutputHandler textOutputHandler) { transform.Translate(Vector2.down * Time.deltaTime, Space.World); float bottom = transform.position.y - halfHeight; if (bottom <= -gameSceneController.screenBounds.y) { textOutputHandler("Enemy at bottom"); //callback delegate gameSceneController.KillObject(this); } }
private void MoveEnemy(TextOutputHandler outputHandler) { var transformObject = transform; transformObject.Translate(Vector2.down * Time.deltaTime, Space.World); float bottom = transformObject.position.y - halfHeight; if (bottom <= -gameSceneController.screenBounds.y) { // outputHandler("Enemy at bottom"); // gameSceneController.KillObject(this); if (EnemyEscaped != null) { // event has subscribers EnemyEscaped(this); } } }