protected override void onHit(GameObject g) { hitList.Add(g); UnitStats targetStats = g.GetComponent <UnitStats>(); float increasedDamage = damage + damage * (1 - targetStats.PercentageHealth()); //deal increased damage equal to percentage missing health if (slowMulti > 1 && targetStats.isSlowed()) { increasedDamage *= slowMulti; } targetStats.TakeDamage(increasedDamage); if (targetStats.CurrentHealth() <= 0) { owner.GetComponent <UnitStats>().GainArmor(armorOnKillAmount); owner.GetComponent <UnitStats>().Heal(healOnKillAmount); } if (bleed > 0) { targetStats.Bleed(bleed); } if (slow > 0) { targetStats.Slow(slow); } if (bleedConsumeMultiplier > 0) { targetStats.ConsumeBleed(bleedConsumeMultiplier); } WeaponCollisionEnterEvent.Invoke(g); OnHitEvent.Invoke(); OnHitHeal.Invoke(heal); }
protected virtual void Start() { statController = GetComponent <UnitStats>(); rigidbody = GetComponent <Rigidbody2D>(); //instantiate health bar HealthbarPrefab = Resources.Load("Prefabs/Healthbar") as GameObject; HealthbarInstance = Instantiate(HealthbarPrefab, transform); HealthbarInstance.transform.localPosition = new Vector3(HealthbarOffsetX, HealthbarOffsetY, 0); HealthbarInstance.transform.localScale = new Vector3(0.5f / transform.localScale.x, 0.5f / transform.localScale.y, 1); HealthbarInstance.GetComponent <HealthBar>().InitMaxHealth((int)statController.MaxHealth()); HealthbarInstance.GetComponent <HealthBar>().UpdateHealth(1, (int)statController.CurrentHealth()); ExposeEffectPrefab = Resources.Load("Prefabs/Effects/ExposeEffect") as GameObject; ProtectionEffectPrefab = Resources.Load("Prefabs/Effects/ProtectionEffect") as GameObject; }