bool Attack(Vector3 atk_pos, TrueGodGameObject defender, float atk, float range) { if (!defender.Is_Dead()) { float distance = Vector3.Distance(atk_pos, defender.Get_OBJ().transform.position); if (distance <= range) { defender.Endure_Attack(atk); if (defender.Is_Dead()) { print(defender.Get_OBJ().name + " Destroyed!!!"); GameObject.Destroy(defender.Get_OBJ()); } return(true); } } return(false); }
int Get_Closest <T>(TrueGodGameObject subject, List <T> objects) where T : TrueGodGameObject { float closest = 1000000; int index = -1; for (int i = 0; i < objects.Count; i++) { if (objects [i].Is_Dead() || subject.Is_Dead()) { continue; } float distance = Vector3.Distance(subject.Get_OBJ().transform.position, objects[i].Get_OBJ().transform.position); if (distance < closest) { closest = distance; index = i; } } return(index); }
bool Attack(TrueGodGameObject attacker, TrueGodGameObject defender) { if (Time.time - attacker.timer >= 1f / attacker.Get_FQC() && !attacker.Is_Dead() && !defender.Is_Dead()) { float distance = Vector3.Distance(attacker.Get_OBJ().transform.position, defender.Get_OBJ().transform.position); if (distance <= attacker.Get_RAG()) { attacker.Launch_Attack(defender); Fire(attacker, defender); attacker.timer = Time.time; if (defender.Is_Dead()) { print(defender.Get_OBJ().name + " Destroyed!!!"); GameObject.Destroy(defender.Get_OBJ()); if (defender.Is_Enemy()) { Add_Score(defender.Get_SCR()); } } return(true); } } return(false); }