private void Die() { // Turn off enemies, harmful objects and enemy spawners EnemySpawnerHoming[] spawners = transform.GetComponentsInChildren <EnemySpawnerHoming>(); foreach (EnemySpawnerHoming esp in spawners) { esp.enabled = false; } GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject go in enemies) { go.GetComponent <EnemyShipHoming>().HitByPlayer(); } AuxFunctions.DestroyGameObjectsWithTag("BossBeam"); AuxFunctions.DestroyGameObjectsWithTag("BossWeakSpot"); StartCoroutine(AuxFunctions.ShakeCamera(1, 3)); // You win animation GameObject.FindGameObjectWithTag("GameController").GetComponent <Animator>().SetTrigger("win"); GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>().WaitAndReload(4); // Stop this script this.enabled = false; }
void Die() { // Stop moving rb.velocity = new Vector2(0, 0); // Turn off enemies, harmful objects and enemy spawners EnemySpawnerHoming[] spawners = transform.GetComponentsInChildren <EnemySpawnerHoming>(); foreach (EnemySpawnerHoming esp in spawners) { esp.enabled = false; } GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject go in enemies) { go.GetComponent <EnemyShipHoming>().HitByPlayer(); } AuxFunctions.DestroyGameObjectsWithTag("BossBeam"); AuxFunctions.DestroyGameObjectsWithTag("BossWeakSpot"); // Animate death animator.SetTrigger("close"); audioSource.PlayOneShot(deathAudio); Instantiate(deathEffect, transform.position, new Quaternion()); StartCoroutine(AuxFunctions.ShakeCamera(1, 3)); // You win animation GameObject.FindGameObjectWithTag("GameController").GetComponent <Animator>().SetTrigger("win"); GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>().WaitAndReload(4); // Stop this script this.enabled = false; }
public void Die() { GetComponent <PlayerController>().enabled = false; GetComponent <Collider2D>().enabled = false; Rigidbody2D[] rbs = GameObject.FindObjectsOfType <Rigidbody2D>(); EnemySpawner[] espwnrs = GameObject.FindObjectsOfType <EnemySpawner>(); /* * foreach (Rigidbody2D rb in rbs) * { * // Bullets run their course, everything else stops * if(rb.transform.tag!="Bullet") * rb.velocity = new Vector2(0, 0); * * } */ foreach (EnemySpawner es in espwnrs) { es.enabled = false; } GetComponent <Animator>().SetTrigger("death"); audioSource.volume = 1.0f; audioSource.PlayOneShot(deathAudio); StartCoroutine(AuxFunctions.ShakeCamera(1, 3)); GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>().WaitAndReload(4); }
public void Die() { GetComponent <PlayerController>().enabled = false; GetComponent <Collider>().enabled = false; Rigidbody[] rbs = GameObject.FindObjectsOfType <Rigidbody>(); EnemySpawner[] espwnrs = GameObject.FindObjectsOfType <EnemySpawner>(); /* * foreach (Rigidbody2D rb in rbs) * { * // Bullets run their course, everything else stops * if(rb.transform.tag!="Bullet") * rb.velocity = new Vector2(0, 0); * * } */ foreach (EnemySpawner es in espwnrs) { es.enabled = false; } // Deactivate meshes and instantiate death particle effect transform.FindChild("Meshes").gameObject.SetActive(false); Instantiate(deathEffect, transform.position, transform.rotation); audioSource.volume = 1.0f; audioSource.PlayOneShot(deathAudio); StartCoroutine(AuxFunctions.ShakeCamera(1, 3)); GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>().WaitAndReload(4); }
// Damage is an optional parameter, averageDamageAmount = 10 by default public void TakeDamage(int damage = 1) { powerups -= damage; powerups = Mathf.Clamp(powerups, -1, maxNumberOfPickups); playerController.numberOfShots--; playerController.numberOfShots = Mathf.Clamp(playerController.numberOfShots, 1, maxNumberOfPickups + 1); if (powerups < 0) { Die(); } else { audioSource.PlayOneShot(hitAudio); StartCoroutine(AuxFunctions.ShakeCamera(0.5f, 0.5f)); } }