public void MaintainData() { //Increment the retries by 1 in_Retries++; //Reset the minutes and the seconds in_Minutes = 0; in_Seconds = 0; //Turn off the bool to restart selection again LM_Script.bl_Selected = false; //Don't destroy this gameobject on load to save data DontDestroyOnLoad(transform.gameObject); //Find all of the NPCs and enable the scripts go_NPCs = GameObject.FindGameObjectsWithTag("NPC"); foreach (GameObject go in go_NPCs) { NPCScript = go.GetComponent <TL_NPC_FSM>(); NPCScript.enabled = true; } //Reload the scene again SceneManager.LoadScene("Level_Area"); }
void Start() { //Locate the gameobjects and obtain their scripts NPCScript = GameObject.Find("pf_NPCGuard(Clone)").GetComponent <TL_NPC_FSM>(); DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>(); //Destroy the bullet gameobject 1.5 seconds later Destroy(gameObject, 1.5f); }
void Start() { //Locate the PC PC = GameObject.FindGameObjectWithTag("PC"); //Obtain the script from the parent gameobject NPCScript = GetComponentInParent <TL_NPC_FSM>(); //Locate the gameobjects and obtain their scripts PCScript = PC.GetComponent <TL_PCStats>(); LM_Script = GameObject.Find("Level_Map").GetComponent <TL_LevelMediator>(); DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>(); }
void CheckPlayerDeath() { //If the PC has less than or equal to 0 health if (fl_Health <= 0) { //Find the game over box in the canvas GameObject GameOverBox = GameObject.Find("PC_Cam(Clone)/Canvas/GameOverBox"); //Activate the game over box GameOverBox.SetActive(true); //Find the text in the canvas GameOverText = GameOverBox.GetComponentInChildren <Text>(); //Set PC health to 0 fl_Health = 0f; //Find all of the NPC's go_NPCs = GameObject.FindGameObjectsWithTag("NPC"); //Disable all of the NPC's scripts foreach (GameObject go in go_NPCs) { NPCScript = go.GetComponent <TL_NPC_FSM>(); NPCScript.enabled = false; } //Disable the movement script on the PC GetComponent <TL_PCMove>().enabled = false; //If the respawn cooldown is less than or equal to 0 if (fl_RespawnCooldown <= 0f) { //Set the respawn cooldown to 0 fl_RespawnCooldown = 0f; //Maintain the data and restart the scene DataScript.MaintainData(); } else { //Subtract the respawn cooldown with the deltatime fl_RespawnCooldown -= Time.deltaTime; } //Display the text and the respawn countdown GameOverText.text = "You died \nRespawning in: " + Mathf.Floor(fl_RespawnCooldown).ToString("F0"); } }
void OnCollisionEnter(Collision Col) { //If the projectile collides with the NPC if (Col.gameObject.tag == "NPC") { //Obtain the script from the collided gameobject NPCScript = Col.gameObject.GetComponent <TL_NPC_FSM>(); //Send a message to the NPC Col.gameObject.SendMessage("ReceiveDamage", fl_Attack, SendMessageOptions.DontRequireReceiver); //If the NPC is either in the patrol, return to post or the flee state if (NPCScript.st_NPC_State == "Patrol" || NPCScript.st_NPC_State == "ReturnToPost" || NPCScript.st_NPC_State == "Flee") { //Increment the player detected variable DataScript.in_PCDetected++; } //Change state to pursue NPCScript.st_NPC_State = "Pursue"; } //Destroy the gameobject Destroy(gameObject); }
void Awake() { DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>(); //Set the layout of the level with a 2D int array in_LevelMap = new int[, ] { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 17, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 }, { 1, 0, 0, 1, 1, 1, 0, 13, 0, 1, 1, 1, 0, 0, 1, 1 }, { 1, 7, 2, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 1, 1 }, { 1, 0, 0, 1, 1, 2, 1, 1, 1, 11, 1, 1, 0, 0, 1, 1 }, { 1, 0, 0, 1, 1, 10, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1 }, { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 }, { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 }, { 1, 0, 0, 0, 0, 0, 1, 15, 1, 0, 0, 0, 0, 0, 1, 1 }, { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 }, { 1, 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, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1 }, { 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1 }, { 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1 }, { 1, 1, 1, 0, 0, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 1 }, { 1, 1, 1, 0, 0, 1, 1, 1, 4, 0, 0, 0, 0, 4, 0, 1 }, { 1, 1, 1, 3, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 }, { 1, 9, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 }, { 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 5, 14, 5, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, }; //Loop through the 2D int array for (int x = 0; x < in_LevelMap.GetLength(0); x++) { for (int z = 0; z < in_LevelMap.GetLength(1); z++) { //If the gameobject level area is null in the 2D array //Map out in the 2D int array, which gameobject gets spawned in the scene depending on what value it is if (go_LevelArea[x, z] == null) { //For example, if the value is 1 in the 2D int array, it spawns a wall in the level if (in_LevelMap[x, z] == 1) { GameObject go_WallClone; go_WallClone = Instantiate(go_Wall, new Vector3(x, 1f, z), Quaternion.identity); go_LevelArea[x, z] = go_WallClone; } if (in_LevelMap[x, z] == 2) { //Declare local variable for the nav mesh agent NavMeshAgent NPCAgent; //Instantiate the NPC go_NPCClone = Instantiate(go_NPC, new Vector3(x, 1f, z), Quaternion.identity); //Set the NPC to the gameobject array go_LevelArea[x, z] = go_NPCClone; //Obtain the nav mesh agent from the NPC NPCAgent = go_LevelArea[x, z].GetComponent <NavMeshAgent>(); //Set a random number between 1 to 100 to the avoidance priority NPCAgent.avoidancePriority = RandomizeNumber(1, 100); } if (in_LevelMap[x, z] == 3) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_A.Add(go_WPClone); WP_List_A.Reverse(); } if (in_LevelMap[x, z] == 4) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_B.Add(go_WPClone); } if (in_LevelMap[x, z] == 5) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_C.Add(go_WPClone); } if (in_LevelMap[x, z] == 6) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_D.Add(go_WPClone); } if (in_LevelMap[x, z] == 7) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_E.Add(go_WPClone); WP_List_E.Reverse(); } if (in_LevelMap[x, z] == 8) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_F.Add(go_WPClone); } if (in_LevelMap[x, z] == 9) { GameObject go_PCClone = Instantiate(go_PC, new Vector3(x, 1f, z), Quaternion.identity);; PCScript = go_PCClone.GetComponent <TL_PCStats>(); GameObject go_CamClone = Instantiate(go_Cam, new Vector3(go_PCClone.transform.position.x + 2f, go_PCClone.transform.position.y + 13f, go_PCClone.transform.position.z), Quaternion.identity); go_CamClone.transform.localEulerAngles = new Vector3(76f, 270f, 0); go_LevelArea[x, z] = go_PCClone; } if (in_LevelMap[x, z] == 10) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_G.Add(go_WPClone); } if (in_LevelMap[x, z] == 11) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_H.Add(go_WPClone); } if (in_LevelMap[x, z] == 12) { go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity); WP_List_I.Add(go_WPClone); WP_List_I.Reverse(); } if (in_LevelMap[x, z] == 13) { GameObject HealthPillClone = Instantiate(go_HealthPill, new Vector3(x, 1f, z), Quaternion.identity); HealthPillClone.transform.localEulerAngles = new Vector3(90f, 0f, 0f); } if (in_LevelMap[x, z] == 14) { GameObject PistolClone = Instantiate(go_Pistol, new Vector3(x, 1f, z), Quaternion.identity); PistolClone.transform.localEulerAngles = new Vector3(90f, 0f, 0f); } if (in_LevelMap[x, z] == 15) { GameObject SmokeGrenadeClone = Instantiate(go_SmokeGrenade, new Vector3(x, 1f, z), Quaternion.identity); SmokeGrenadeClone.transform.localEulerAngles = new Vector3(90f, 0f, 0f); } if (in_LevelMap[x, z] == 16) { GameObject AmmoClone = Instantiate(go_Ammo, new Vector3(x, 1f, z), Quaternion.identity); AmmoClone.transform.localEulerAngles = new Vector3(90f, 0f, 0f); } if (in_LevelMap[x, z] == 17) { GameObject go_EndGameClone = Instantiate(go_EndGame, new Vector3(x, 1f, z), Quaternion.identity); go_EndGameClone.transform.eulerAngles = new Vector3(90f, 270f, 0); } } } } //Temporary lists to store certain elements from another list to swap them List <GameObject> Swap_List_E = new List <GameObject>(); List <GameObject> Swap_List_I = new List <GameObject>(); List <GameObject> Swap_List_C = new List <GameObject>(); Master_List.Add(WP_List_F); for (int f = 0; f < WP_List_F.Count; f++) { WP_List_F[f].name = f.ToString(); } Master_List.Add(WP_List_G); for (int g = 0; g < WP_List_G.Count; g++) { WP_List_G[g].name = g.ToString(); } Master_List.Add(WP_List_H); for (int h = 0; h < WP_List_H.Count; h++) { WP_List_H[h].name = h.ToString(); } Swap_List_E.Add(WP_List_E[2]); //Adds index 2 element of the WP List into index 1 element of the temporary list Swap_List_E.Add(WP_List_E[1]); //Adds index 1 element of the WP List into index 2 element of the temporary list WP_List_E.RemoveRange(1, 2); //Removes a range of old elements from the list WP_List_E.Insert(1, Swap_List_E[0]); //Inserts index 0 element of the temporary list into index 1 of the WP List WP_List_E.Insert(2, Swap_List_E[1]); //Inserts index 1 element of the temporary list into index 2 of the WP List //Adds the WP List into the master list Master_List.Add(WP_List_E); for (int e = 0; e < WP_List_E.Count; e++) { WP_List_E[e].name = e.ToString(); } Master_List.Add(WP_List_D); for (int d = 0; d < WP_List_D.Count; d++) { WP_List_D[d].name = d.ToString(); } Swap_List_I.Add(WP_List_I[2]); //Adds index 2 element of the WP List into index 1 element of the temporary list Swap_List_I.Add(WP_List_I[1]); //Adds index 1 element of the WP List into index 2 element of the temporary list WP_List_I.RemoveRange(1, 2); //Removes a range of old elements from the list WP_List_I.Insert(1, Swap_List_I[0]); //Inserts index 0 element of the temporary list into index 1 of the WP List WP_List_I.Insert(2, Swap_List_I[1]); //Inserts index 1 element of the temporary list into index 2 of the WP List Master_List.Add(WP_List_I); for (int i = 0; i < WP_List_I.Count; i++) { WP_List_I[i].name = i.ToString(); } Master_List.Add(WP_List_A); for (int a = 0; a < WP_List_A.Count; a++) { WP_List_A[a].name = a.ToString(); } Swap_List_C.Add(WP_List_C[2]); //Adds index 2 element of the WP List into index 1 element of the temporary list Swap_List_C.Add(WP_List_C[1]); //Adds index 1 element of the WP List into index 2 element of the temporary list WP_List_C.RemoveRange(1, 2); //Removes a range of old elements from the list WP_List_C.Insert(1, Swap_List_C[0]); //Inserts index 0 element of the temporary list into index 1 of the WP List WP_List_C.Insert(2, Swap_List_C[1]); //Inserts index 1 element of the temporary list into index 2 of the WP List Master_List.Add(WP_List_C); for (int c = 0; c < WP_List_C.Count; c++) { //Name the waypoints depending on the value from the for loop WP_List_C[c].name = c.ToString(); } Master_List.Add(WP_List_B); for (int b = 0; b < WP_List_B.Count; b++) { //Name the waypoints depending on the value from the for loop WP_List_B[b].name = b.ToString(); } for (int x = 0; x < in_LevelMap.GetLength(0); x++) { for (int z = 0; z < in_LevelMap.GetLength(1); z++) { if (go_LevelArea[x, z] != null) { //If the gameobject in the 2D array is the NPC if (go_LevelArea[x, z].transform.tag == "NPC") { //Obtain the script from the NPC NPCScript = go_LevelArea[x, z].GetComponent <TL_NPC_FSM>(); //Assign the waypoints for the NPC NPCScript.WP_Assignment(Master_List[in_Master_List_Index]); //Assign the ID for waypoints NPCScript.ID_TrailAssignment(in_Master_List_Index); //Increment the index for the master list in_Master_List_Index++; //If it is more than 7, break the loop if (in_Master_List_Index > 7) { break; } } } } } //Build the navmesh #if UNITY_EDITOR UnityEditor.AI.NavMeshBuilder.BuildNavMesh(); #endif }