IEnumerator Attack(Transform[] _targetList) { Transform[] Worlds = ClosestWorld(_targetList, false); World WorldScript = null; if (Worlds.Length == 1) { WorldScript = Worlds[0].GetComponent <World>(); } else { foreach (var world in Worlds) { if (GetComponent <World>().WorldPopulation > world.GetComponent <World>().WorldPopulation) { WorldScript = world.GetComponent <World>(); } } } if (WorldScript.WorldPopulation < GetComponent <World>().WorldPopulation) { Debug.Log(transform.name + " Moving to " + Worlds[0].name); //attack InvaderControl invaderScript = transform.GetComponent <InvaderControl>(); invaderScript.Attack(gameObject, Worlds[0].gameObject); } Debug.Log(transform.name + " cannot attack"); yield return(null); }
public static bool AddToSelection(GameObject selectedWorld) { //MAX SELCTION == 2 if (SelectedPlanets.Count == 0 && PlayerTags.Contains(selectedWorld.tag)) { SelectedPlanets.Add(selectedWorld); return(true); } if (SelectedPlanets.Count == MaxSelected - 1) { //<attack function> InvaderControl invaderScript = selectedWorld.GetComponent <InvaderControl>(); invaderScript.Attack(SelectedPlanets[0], selectedWorld); DeselectAll(); return(false); } return(false); }