void resetLevel() { //==============================================// // Change for each to for loop to reduce GC // //==============================================// sendBack = true; // Get all the objects from the scene using tag (Might have performance impact, if have time find a better solution) allEnemies = GameObject.FindGameObjectsWithTag("Enemy"); allHunters = GameObject.FindGameObjectsWithTag("HuntingDog"); allKeys = GameObject.FindGameObjectsWithTag("Key"); allDoors = GameObject.FindGameObjectsWithTag("Door"); allDestructibles = GameObject.FindGameObjectsWithTag("Destructible"); allBottles = GameObject.FindGameObjectsWithTag ("Bottle"); allBones = GameObject.FindGameObjectsWithTag("Bone"); allFatDogs = GameObject.FindGameObjectsWithTag("FatDog"); allSpheres = GameObject.FindGameObjectsWithTag("SoundSphere"); allClosets = GameObject.FindGameObjectsWithTag ("Closet"); //resets BGM. chaseTransScript.resetChaseTrans(); // foreach(GameObject hunter in allHunters) // { // hunterScript = (huntingDog)hunter.GetComponent<huntingDog>(); // hunterScript.selfDestruct(); // //Destroy(hunter); // } // foreach(GameObject fatDog in allFatDogs) // { // fatDogScript = (fatDogAi)fatDog.GetComponent<fatDogAi>(); //// fatDogScript.agent.Stop(); //// fatDogScript.agent.velocity = Vector3.zero; //// fatDogScript.GetComponent<Rigidbody>().velocity = Vector3.zero; //// fatDogScript.GetComponent<Rigidbody>().angularVelocity = Vector3.zero; //// if (fatDogScript.respawnPosition != null) //// { //// fatDogScript.transform.position = fatDogScript.respawnPosition; //// } //// fatDogScript.stateManager(4); // // Reset func contains everything above // fatDogScript.Reset (); // } int i = 0; // if (allDestructibles.Length > 0) // { // for (i = 0; i < allDestructibles.Length; i++) // { // destructibleSpawner = allDestructibles[i].GetComponent<instantiateDestructible> (); // destructibleSpawner.checkpoint (); // } // } if (allDestructibles.Length > 0) { for (i = 0; i < allDestructibles.Length; i++) { destructibleSpawner = allDestructibles[i].GetComponent<instantiateDestructible> (); destructibleSpawner.checkpoint (); } } for (i = 0; i < allBottles.Length; i++) { if (allBottles[i].GetComponent<breakableObject>() == null) { Debug.Log (allBottles[i]); } } if (allBottles.Length > 0) { for (i = 0; i < allBottles.Length; i++) { // if (allBottles[i].GetComponent<breakableObject>() == null) // { // Debug.Log (allBottles[i]); // } // bo = allBottles[i].GetComponent<breakableObject>(); // bo.brokenPieces.SetActive(false); // bo.originalObject.SetActive(true); // bo.GetComponent<CapsuleCollider>().enabled = true; allBottles[i].GetComponent<breakableObject>().Reset(); } } if (allSpheres.Length > 0) { for (i = 0; i < allSpheres.Length; i++) { allSpheres[i].SetActive(false); } } if (allBones.Length > 0) { for (i = 0; i < allBones.Length; i++) { player.GetComponent<TemporaryMovement> ().reduceBonePlacedNumber (); Destroy (allBones[i]); } } if (allHunters.Length > 0) { for (i = 0; i < allHunters.Length; i++) { hunterScript = allHunters [i].GetComponent<huntingDog> (); hunterScript.selfDestruct (); } } if (allFatDogs.Length > 0) { for (i = 0; i < allFatDogs.Length; i++) { fatDogScript = allFatDogs [i].GetComponent<fatDogAi> (); fatDogScript.Reset (); } } if (allEnemies.Length > 0) { for (i = 0; i < allEnemies.Length; i++) { script = (enemyPathfinding)allEnemies[i].GetComponent<enemyPathfinding> (); script.agent.Stop (); script.agent.velocity = Vector3.zero; script.GetComponent<Rigidbody> ().velocity = Vector3.zero; script.GetComponent<Rigidbody> ().angularVelocity = Vector3.zero; if (script.respawnPosition != null) { script.transform.position = script.respawnPosition; } script.currentTarget = script.firstTarget; script.targetCounter = 0; script.agent.speed = script.patrolSpeed; script.stateManager (1); script.agent.SetDestination (script.currentTarget.position); script.newTargetTimer = script.defaultNewTargetTimer; } } if (allKeys.Length > 0) { for (i = 0; i < allKeys.Length; i++) { keySpawner = allKeys[i].GetComponent<instantiateKey> (); keySpawner.checkpoint (); } } if (allDoors.Length > 0) { for (i = 0; i < allDoors.Length; i++) { door = allDoors[i].GetComponent<DoorTrigger> (); door.checkpoint (); } } if (allClosets.Length > 0) { for (i = 0; i < allClosets.Length; i++) { closet = allClosets[i].GetComponent<hidingThirdPerson>(); closet.ResetCloset (); } } playerScript.resetCharacter(); StopAllCoroutines (); sendBack = false; }
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag ("Enemy")) { script = other.GetComponent<enemyPathfinding>(); smellDetected = true; } else if(other.gameObject.CompareTag ("HuntingDog")) { huntingDogScript = other.GetComponent<huntingDog>(); smellDetected = true; } else if(other.gameObject.CompareTag ("FatDog")) { scriptFatDog = other.GetComponent<fatDogAi>(); smellDetected = true; } else if(other.gameObject.CompareTag ("Looker")) { if (other.transform.parent.CompareTag ("Enemy")) { script = other.transform.parent.GetComponent<enemyPathfinding>(); smellDetected = true; } else if (other.transform.parent.CompareTag ("HuntingDog")) { huntingDogScript = other.transform.parent.GetComponent<huntingDog>(); smellDetected = true; } else if (other.transform.parent.CompareTag ("FatDog")) { scriptFatDog = other.transform.parent.GetComponent<fatDogAi>(); smellDetected = true; } } }
void Start() { chaseTransScript = GameObject.Find("BGM").GetComponent<chaseTransition>(); range = startRange; width = startWidth; height = startHeight; if (this.transform.parent.GetComponent<enemyPathfinding>() != null) { script = this.transform.parent.GetComponent<enemyPathfinding>(); } if (this.transform.parent.GetComponent<fatDogAi>() != null) { scriptFatDog = this.transform.parent.GetComponent<fatDogAi>(); } if (transform.parent.GetComponent<huntingDog>() != null) { scriptHuntingDog = transform.parent.GetComponent<huntingDog>(); } parent = this.transform.parent; //if (transform.localScale.x < width || transform.localScale.x > width) //{ transform.localScale = new Vector3(width, height, range); //} }