Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EnemyHealth : MonoBehaviour {
- public float currentHealth;
- [SerializeField]
- float startingHealth;
- public EnemySpawner spawner;
- void Awake()
- {
- currentHealth = startingHealth;
- }
- public void TakeDamage(float damage)
- {
- currentHealth -= damage;
- if (currentHealth <= 0f)
- {
- Die();
- }
- }
- void Die()
- {
- // spawn faster each time you kill an enemy
- if (spawner.spawnDelay > 1)
- {
- spawner.spawnDelay -= .1f;
- }
- // access static variable on another script
- EnemySpawner.totalNumberOfEnemies--;
- if (EnemySpawner.totalNumberOfEnemies <= 0)
- {
- // Do win game here.
- }
- //SceneManager.LoadScene(0);
- gameObject.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement