public void OnDestroy(object sender, GameObject gameObject) { switch (gameObject) { case Player g: Player.Fire -= AddBullet; _enemyController.CreateEnemy -= OnCreateEnemy; foreach (var enemy in _enemies) { enemy.OnDestroy(); } foreach (var bullet in _bullets) { bullet.OnDestroy(); } break; case Enemy g: EnemyDestroyed?.Invoke(this, gameObject); break; } gameObject.Destroy -= OnDestroy; _removingObjects.Add(gameObject); }
protected void Die() { // TODO: Do some cool explosion animations or something and then end level EnemyDestroyed?.Invoke(this, EventArgs.Empty); Destroy(this); }
void ShootAt(EnemyDestroyed e) { GameObject bulletGO = (GameObject)Instantiate(bulletPrefab, this.transform.position, this.transform.rotation); Bullet b = bulletGO.GetComponent <Bullet>(); b.target = e.transform; }
void DestroyEnemy() { Destroy(CurrentEnemy.obj); CurrentEnemy = null; EnemyDestroyed?.Invoke(); GameManager.obj.OnEnemyKilled(); PackGridManager.obj.RemoveAll(GridObject.Type.JUNK); }
private void OnHit(float damage) { currentHp -= damage; if (currentHp <= 0) { EnemyDestroyed.Trigger(this); } }
protected void OnCollisionEnter2D(Collision2D col) { if (EnemyDestroyed != null) { EnemyDestroyed.Invoke(); } Instantiate(deathParticles, transform.position, transform.rotation); Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { if (other.gameObject.layer == PROJECTILE_LAYER) { Destroy(other.gameObject); life--; if (life <= 0) { EnemyDestroyed?.Invoke(this); Destroy(gameObject); } } }
protected virtual void HitByBullet(GameObject other) { Debug.Log("particle collision"); hitsRemaining--; if (hitsRemaining < 1) { EnemyDestroyed?.Invoke(hitsToKill, transform.position); Destroy(gameObject); } //var part = other.GetComponent<ParticleSystem>(); //int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents); //int i = 0; //while (i < numCollisionEvents) //{ // Debug.Log("particle collision"); // i++; //} }
void Update() { EnemyDestroyed[] enemies = GameObject.FindObjectsOfType <EnemyDestroyed>(); EnemyDestroyed nearestEnemy = null; float dist = Mathf.Infinity; foreach (EnemyDestroyed e in enemies) { float d = Vector3.Distance(this.transform.position, e.transform.position); if (nearestEnemy == null || d < dist) { nearestEnemy = e; dist = d; } } if (nearestEnemy == null) { Debug.Log("No enemies?"); return; } Vector3 dir = nearestEnemy.transform.position - this.transform.position; Quaternion lookRot = Quaternion.LookRotation(dir); turretTransform.rotation = Quaternion.Euler(0, lookRot.eulerAngles.y, 0); fireCooldownLeft -= Time.deltaTime; if (fireCooldownLeft <= 0 && dir.magnitude <= range) { fireCooldownLeft = fireCooldown; ShootAt(nearestEnemy); } }
public static void CallEnemyDestroyed(int pointValue) { EnemyDestroyed?.Invoke(pointValue); }