Guest User

Untitled

a guest
Dec 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Health_Armor : MonoBehaviour {
  6. public float health;
  7. public float armor;
  8.  
  9.  
  10.  
  11.  
  12. // Use this for initialization
  13. void Start () {
  14. health = 100f;
  15. armor = 20f;
  16.  
  17. }
  18.  
  19. // Update is called once per frame
  20. void Update ()
  21. {
  22.  
  23. Max_Min_Stats();
  24.  
  25. }
  26.  
  27. private void Max_Min_Stats()
  28. {
  29. if(health >= 100f)
  30. {
  31. health = 100f;
  32. }
  33.  
  34. if (health <= 0f)
  35. {
  36. health = 0f;
  37. }
  38.  
  39. if (armor >= 100f)
  40. {
  41. armor = 100f;
  42. }
  43.  
  44. if (armor <= 0f)
  45. {
  46. armor = 0f;
  47. }
  48. }
  49.  
  50. public void TakeDamage(float amount)
  51. {
  52. armor -= amount;
  53. if (armor <= 0f)
  54. {
  55. health -= amount;
  56. if (health <= 0f)
  57. {
  58. Death();
  59. }
  60. }
  61. }
  62.  
  63. private void Death()
  64. {
  65. Destroy(gameObject);
  66. }
  67.  
  68. }
Add Comment
Please, Sign In to add comment