// passes lead to next wingman, if any available public void Death() { if (statusInFormation == StatusInFormation.lead) { GameObject formation4 = gameObject.transform.Find("Formation4(Clone)").gameObject; bool leadAssigned = false; int pos = 0; for (int i = 0; i <= 2; i++) { // Set up the new formation lead before death, rawr if (!leadAssigned && wingmen[i]) { wingmen[i].GetComponent <VesselAI>().statusInFormation = StatusInFormation.lead; wingmen[i].GetComponent <VesselAI>().flightStatus = FlightStatus.sentry; wingmen[i].GetComponent <VesselAI>().teamManager = teamManager; wingmen[i].GetComponent <VesselAI>().formationBogies.Clear(); wingmen[i].GetComponent <VesselAI>().formationBogies = formationBogies; teamManager.NewFormationLead(gameObject, wingmen[i]); formation4.transform.parent = wingmen[i].transform; formation4.transform.localPosition = new Vector3(0, 0, 0); formation4.transform.localRotation.SetEulerAngles(wingmen[i].transform.rotation.eulerAngles); // Reassign wingmen to new lead for (int j = i + 1; j <= 2; j++) { if (wingmen[j]) { wingmen[i].GetComponent <VesselAI>().wingmen[pos] = wingmen[j]; VesselAI wmAI = wingmen[i].GetComponent <VesselAI>().wingmen[pos].GetComponent <VesselAI>(); wmAI.formationLead = wingmen[i]; wmAI.statusInFormation = (VesselAI.StatusInFormation)(pos + 1); wmAI.wingmanState = WingmanState.inFormation; wmAI.statusText.text = ("newpos: " + pos); pos++; } } leadAssigned = true; } } } }
// Some tuning required void InstantiateFightersInFormation(GameObject fighterPrefab, Vector3[] formationPositions, int i, int managerNr) { GameObject formationLead = null; GameObject formation = Instantiate(formation4Prefab, formationPositions[i], Quaternion.identity); formationLead = null; bool leadVessel = true; int wingmanNr = 0; foreach (Transform fPosition in formation.transform) { GameObject vessel = Instantiate(fighterPrefab, fPosition.position, Quaternion.identity) as GameObject; VesselAI vesselAI = vessel.GetComponent <VesselAI>(); if (leadVessel) { vesselAI.statusInFormation = VesselAI.StatusInFormation.lead; vesselAI.flightStatus = VesselAI.FlightStatus.patrolling; formationLead = vessel; teamManagers[managerNr].formations.Add(new LFAI.Formation(vessel)); teamManagers[managerNr].teamAssets.fighterAmount++; leadVessel = false; } else { vesselAI.statusInFormation = (VesselAI.StatusInFormation)(wingmanNr + 1); vesselAI.formationLead = formationLead; vesselAI.wingmanState = VesselAI.WingmanState.inFormation; vesselAI.flightStatus = VesselAI.FlightStatus.sentry; formationLead.GetComponent <VesselAI>().wingmen[wingmanNr] = vessel; wingmanNr++; teamManagers[managerNr].teamAssets.fighterAmount++; } vesselAI.teamManager = teamManagers[managerNr]; vesselAI.teamSide = (TeamManager.TeamSide)managerNr; } if (formationLead) { formation.transform.parent = formationLead.transform; for (int j = 0; j <= 2; j++) { // formationLead.GetComponent<VesselAI>().wingmen[j] = formation.transform.Find("Position" + (j + 2).ToString()).gameObject; } } }