Advertisement
keivy349

Untitled

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