Advertisement
keivy349

Untitled

Mar 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public abstract class DestrutiveBase : MonoBehaviour {
  6.  
  7. public int currentLife;
  8. protected bool isDead;
  9. public BasicStats startLife;
  10. public Transform lifeBar;
  11. //public GameObject LifeBarUI;
  12. private Vector3 startSizeLifeBar;
  13. private Vector3 currentSizeLifeBar;
  14.  
  15. // Use this for initialization
  16. protected void Start () {
  17.  
  18. //LifeBarUI.SetActive (false);
  19. startSizeLifeBar = lifeBar.localScale;
  20. currentSizeLifeBar = lifeBar.localScale;
  21. }
  22.  
  23. // Update is called once per frame
  24. protected void Update () {
  25.  
  26. }
  27.  
  28. public void ApplyDamage(int damage){
  29. if(isDead) return;
  30.  
  31. currentLife -= damage;
  32.  
  33. if(currentLife <= 0){
  34. isDead = true;
  35. OnDestroyed ();
  36. }
  37.  
  38. currentSizeLifeBar.x = currentLife*startSizeLifeBar.x/BasicStats.startLife;
  39.  
  40. if(currentSizeLifeBar.x < 0)
  41. currentSizeLifeBar.x = 0;
  42.  
  43. lifeBar.localScale = currentSizeLifeBar;
  44.  
  45. OnApplyDamage ();
  46. }
  47.  
  48. public abstract void OnDestroyed();
  49. public abstract void OnApplyDamage();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement