Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1.     public IEnumerator TakeWorldDamage(float damagePerSecond)
  2.     {
  3.         while (canTakeDamage)
  4.         {
  5.             health -= damagePerSecond;
  6.             health = Mathf.Clamp(health, 0.0f, maxHealth);
  7.             Debug.Log("You took " + damagePerSecond + " damage from the world.");
  8.             yield return new WaitForSeconds(1.0f);
  9.         }
  10.     }
  11.  
  12.     public void OnTriggerEnter(Collider other)
  13.     {
  14.         if (other.tag == "Lava")
  15.         {
  16.             canTakeDamage = true;
  17.             StartCoroutine(TakeWorldDamage(10.0f));
  18.         }
  19.     }
  20.  
  21.     public void OnTriggerExit(Collider other)
  22.     {
  23.         if (other.tag == "Lava")
  24.         {
  25.             canTakeDamage = false;
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement