Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public abstract class DestrutiveBase : MonoBehaviour {
- public int currentLife;
- protected bool isDead;
- public BasicStats startLife;
- public Transform lifeBar;
- //public GameObject LifeBarUI;
- private Vector3 startSizeLifeBar;
- private Vector3 currentSizeLifeBar;
- // Use this for initialization
- protected void Start () {
- //LifeBarUI.SetActive (false);
- startSizeLifeBar = lifeBar.localScale;
- currentSizeLifeBar = lifeBar.localScale;
- }
- // Update is called once per frame
- protected void Update () {
- }
- public void ApplyDamage(int damage){
- if(isDead) return;
- currentLife -= damage;
- if(currentLife <= 0){
- isDead = true;
- OnDestroyed ();
- }
- currentSizeLifeBar.x = currentLife*startSizeLifeBar.x/BasicStats.startLife;
- if(currentSizeLifeBar.x < 0)
- currentSizeLifeBar.x = 0;
- lifeBar.localScale = currentSizeLifeBar;
- OnApplyDamage ();
- }
- public abstract void OnDestroyed();
- public abstract void OnApplyDamage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement