public void GetNewMissionToSinglePlayer(GameObject Player) { // destroy old MissionBase oldMission = Player.GetComponent <MissionBase>(); if (oldMission != null) { InstantiatedMissions.Remove(oldMission); oldMission.DestroyMission(); } // get new mission MissionBase newMission = GetUniqueMission(); string scriptName = newMission.ToString(); Player.AddComponent(scriptName); Player.GetComponent <MissionBase>().InitializeMission(Player, newMission); InstantiatedMissions.Add(Player.GetComponent <MissionBase>()); }
public void GetNewMissions() { // set up all the lists Players = GameManager.Instance.Players; AlreadyChosenMissions = new List <MissionBase>(Players.Count); AllAvailableMissionsTotal = new List <MissionBase>(4); InstantiatedMissions = new List <MissionBase>(Players.Count); if (MissionTexts.Count != 4) { Debug.Log("ERROR - Mission Manager needs to have 4 links to TextMesh!"); } // find all the missions parented to this game object MissionBase[] allChildren = GetComponentsInChildren <MissionBase>(); foreach (MissionBase mission in allChildren) { AllAvailableMissionsTotal.Add(mission); } if (AllAvailableMissionsTotal.Count < 4) { Debug.Log("ERROR - at least 4 missions needs to be assigned to Mission Manager!"); } if (MissionTexts.Count != 4) { Debug.Log("ERROR - 4 missions texts needs to be assigned to Mission Manager!"); } if (MissionIcons.Count != 4) { Debug.Log("ERROR - 4 missions icons needs to be assigned to Mission Manager!"); } // choose four missions out of the total amount FourPotentialMissionsAvailable = ChooseMissionsFromSet(4, AllAvailableMissionsTotal); ShuffleMissions(FourPotentialMissionsAvailable); // set up template stuff that is only called once per mission foreach (MissionBase m in FourPotentialMissionsAvailable) { m.TemplateSetUp(); } // set the rumble states for each mission (1, 2, 3, 4) for (int i = 1; i < 5; i++) { FourPotentialMissionsAvailable[i - 1].MissionIDRumble = i; } // destroy all missions on players // NOTE: players should only have 1 active mission at the same time! for (int i = 0; i < Players.Count; i++) { //Players[i].GetComponent<Player>().RemoveAllMissionsOnMe(); // does not work MissionBase m = Players[i].GetComponent <MissionBase>(); //DestroyImmediate(m); if (m != null) { InstantiatedMissions.Remove(m); m.DestroyMission(); } } // assign new missions for (int i = 0; i < Players.Count; i++) { MissionBase c = GetUniqueMission(); // find a "relatively random" mission string scriptName = c.ToString(); // get name of mission script so it can be attached to player Players[i].AddComponent(scriptName); Players[i].GetComponent <MissionBase>().InitializeMission(Players[i], c); // set up various stuff on mission via the template mission //Players[i].name = Players[i].GetComponent<Player>().Name + "_" + scriptName; InstantiatedMissions.Add(Players[i].GetComponent <MissionBase>()); // list of the current missions, easy to see in Inspector } // set the GUI things SetTextAndIcons(); }