public void Damage(int dmg, Vector3 source, string tg = "") { if (Morale <= 0) { return; } if (gameObject.tag == tg) { dmg *= -1; //Morale -= dmg; } if (dmg > 0) { if (!float.IsInfinity(source[0])) { damagesources.Add(source - transform.position); } CalcResistance(); dmg = Mathf.Max(1, dmg - damageresistance); } Morale -= dmg; if (Morale > MaxMorale) { Morale = MaxMorale; } unitCanvas.SetCurrentMP(Morale); StartCoroutine(unitCanvas.DamageAnimation(-dmg)); if (Morale <= 0) { movesPerTurn = 0; movesLeft = 0; gridController.RemoveEntity(gameObject); GameObject newflag = Instantiate(whiteFlagPrefab, transform, false); newflag.transform.localPosition = handlocation; gridController.getPath(Vector3Int.FloorToInt(transform.position), Vector3Int.one, steps, 200, true); dieAfterMove = true; /*if (tag == "EnemyUnit") * { * gridController.defeatedfoes++; * }*/ //Destroy(gameObject); } }