From 8139cd89a52559cdd906cd5866dcc55dbd7003a7 Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Fri, 15 Dec 2023 20:14:49 +0000 Subject: [PATCH] Merge branch 'release/v_0.0.1' --- Assets/Scripts/Damageable.cs | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 92 insertions(+), 0 deletions(-) diff --git a/Assets/Scripts/Damageable.cs b/Assets/Scripts/Damageable.cs new file mode 100644 index 0000000..52da994 --- /dev/null +++ b/Assets/Scripts/Damageable.cs @@ -0,0 +1,92 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Damageable : MonoBehaviour +{ + // ONLY FOR DEBUG USE + [SerializeField] + private bool selfDamage = false; + Animator animator; + + [SerializeField] + private int _maxHealth = 100; + [SerializeField] + private int _health = 100; + [SerializeField] + private bool _isAlive = true; + [SerializeField] + private bool isInvincible = false; + private float timeSinceHit = 0f; + public float invincibilityTime = 0.25f; + + public int MaxHealth + { + get { return _maxHealth; } + set { _maxHealth = value; } + } + public int Health + { + get { return _health; } + set + { + if (value > MaxHealth) + { + + Debug.Log("Warum?"); + _health = MaxHealth; + } + else + { + _health = value; + } + if (value <= 0) + { + IsAlive = false; + } + } + } + public bool IsAlive + { + get { return _isAlive; } + private set + { + _isAlive = value; + animator.SetBool(AnimationStrings.isAlive, value); + } + } + + private void Awake() + { + //Health = MaxHealth; + animator = GetComponent<Animator>(); + } + private void Update() + { + if (isInvincible) + { + if (timeSinceHit > invincibilityTime) + { + isInvincible = false; + timeSinceHit = 0; + } + else + { + timeSinceHit += Time.deltaTime; + } + } + if (selfDamage) + { + Hit(10); + } + } + + public void Hit(int damage) + { + if (IsAlive && !isInvincible) + { + Health -= damage; + isInvincible = true; + } + } +} -- Gitblit v1.9.3