Advertisement
talmud

Untitled

Oct 17th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyHealth : MonoBehaviour {
  6.  
  7.  
  8. public float currentHealth;
  9.  
  10. [SerializeField]
  11. float startingHealth;
  12.  
  13. public EnemySpawner spawner;
  14.  
  15. void Awake()
  16. {
  17. currentHealth = startingHealth;
  18. }
  19.  
  20. public void TakeDamage(float damage)
  21. {
  22. currentHealth -= damage;
  23. if (currentHealth <= 0f)
  24. {
  25. Die();
  26. }
  27. }
  28.  
  29. void Die()
  30. {
  31. // spawn faster each time you kill an enemy
  32. if (spawner.spawnDelay > 1)
  33. {
  34. spawner.spawnDelay -= .1f;
  35. }
  36.  
  37. // access static variable on another script
  38. EnemySpawner.totalNumberOfEnemies--;
  39. if (EnemySpawner.totalNumberOfEnemies <= 0)
  40. {
  41. // Do win game here.
  42. }
  43.  
  44. //SceneManager.LoadScene(0);
  45. gameObject.SetActive(false);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement