private void OnCollisionEnter2D(Collision2D other) { EnemyRobotController enemyRobot = other.collider.GetComponent <EnemyRobotController>(); if (other != null) { if (enemyRobot && !this.isInvincible) { this.PlaySound(this.sfxRubyHit); this.ChangeHealth(-1); } } }
//Instantiate Enemy Prefabs while parsing occurs void GenerateEnemy(int horizontal, int vertical, PlayerMoveSet[] enemyMoveSet) { //Occupy the spot _tiles[horizontal, vertical].isOccupied = true; //get position data for enemy Vector3 tempPos; tempPos.x = _tiles [horizontal, vertical].x; tempPos.y = _tiles [horizontal, vertical].y + _tileGridData.robotFootingOffset; tempPos.z = -1f; GameObject tempEnemyObject = Instantiate(_enemyRobotPrefab, tempPos, _enemyRobotFacingLeftRotation, this.transform); _tempEnemyRobotController = tempEnemyObject.GetComponent <EnemyRobotController>(); _enemyRobotControllers.Add(_tempEnemyRobotController); _tempEnemyRobotController.InitializeEnemy(horizontal, vertical, enemyMoveSet); }
private void OnTriggerEnter2D(Collider2D collision) { Enemy e = collision.GetComponent <Enemy>(); if (e != null) { e.ChangeHealth(-1); } EnemyRobotController e2 = collision.GetComponent <EnemyRobotController>(); if (e2 != null) { e2.Fix(); } Destroy(gameObject); }
private void OnCollisionEnter2D(Collision2D other) { ParticleSystem cogCollisionEffect = Instantiate( this.projectileCollisionPrefab, this.rigidbody2d.position, Quaternion.identity); EnemyRobotController enemy = other.collider.GetComponent <EnemyRobotController>(); if (enemy != null) { enemy.Fix(); } Destroy(gameObject); this.timer = this.resetTimer; }
//Called by playerRobotController.cs to find the correct enemy to destroy public void DestroyEnemy(int hCnt, int vCnt) { bool enemyToDestroyFound = false; IEnumerator <EnemyRobotController> iEnum = _enemyRobotControllers.GetEnumerator(); iEnum.Reset(); while (iEnum.MoveNext() && !enemyToDestroyFound) { EnemyRobotController tempEnemyController = iEnum.Current; if (tempEnemyController.CurrentHorizontalIndex == hCnt) { if (tempEnemyController.CurrentVerticalIndex == vCnt) { tempEnemyController.DestroyEnemyRobot(); enemyToDestroyFound = true; } } } }