void Update() { if (this.transform.position.x <= endpoint) { spawn.AddScore(ScoreValue); Destroy(this.gameObject); } }
private void KillEnemy() { enemySpawner.AddScore(); // important to instantiate before destroying this object var vfx = Instantiate(deathParticlePrefab, transform.position, Quaternion.identity); vfx.Play(); Destroy(vfx.gameObject, vfx.main.duration); AudioSource.PlayClipAtPoint(enemyDeathSFX, Camera.main.transform.position); Destroy(gameObject); }
private void KillEnemy() { var playDeathPart = Instantiate(deathFx, transform.position, Quaternion.identity); float destroyDelay = playDeathPart.main.duration; if (tag == "EnemyBig") { BonusPoints(); // Controls the bonus Gameobject into friendly field enemySpawner.AddScore(scoreValue); playDeathPart.Play(); Destroy(playDeathPart.gameObject, destroyDelay); Destroy(gameObject); } else { // I have the Particle destroying itself through the Editor. playDeathPart.Play(); enemySpawner.AddScore(scoreValue); Destroy(playDeathPart.gameObject, destroyDelay); Destroy(gameObject); } }
void Update() { shootTimer += Time.deltaTime; transform.Translate(Vector3.down * speed * Time.deltaTime); if (shootTimer > 1f) { Instantiate(laserPrefab, new Vector3(transform.position.x - 0.8f, transform.position.y, 1), Quaternion.Euler(0, 0, 90)); gameObject.GetComponent <AudioSource>().PlayOneShot(laserShot); shootTimer = 0; } if (transform.position.x < -8) { Destroy(gameObject); } if (amountOfEnemyHP <= 0) { Destroy(gameObject); if (EnemySpawner.gameMode == 1) { enemySpawner.AddScore(scoreValue); } Instantiate(explosion, transform.position, Quaternion.identity); } }