void EndEpisode() { GameObject[] Remained = inspector.getCurrentUnits(); foreach (GameObject unit in Remained) { if (inspector.setScriptsFrom(unit)) { if (inspector.getScriptType() == "Unit") { inspector.removeFrom(unit); Destroy(unit); } else if (inspector.getScriptType() == "AgentScript") { Debug.LogWarning("Agent Remained after episode ends"); } } } sys.battleStarted = false; System.Array.Resize(ref sys.knightUnits, 0); System.Array.Resize(ref sys.enemyUnits, 0); foreach (GameObject unit in inspector.getInstantiatedUnits()) { Destroy(unit); } foreach (GameObject corpe in GameObject.FindGameObjectsWithTag("Ragdoll")) { corpe.GetComponent <DeleteParticles>().DestroyMe(); } }
//get all units in range of a certain position public GameObject unitsInRange(Vector3 position) { //store the units in an array GameObject[] allUnits = inspector.getInstantiatedUnits(); //foreach unit, check if it's in range and return as soon as one of them is foreach (GameObject unit in allUnits) { if (Vector3.Distance(unit.transform.position, position) < levelData.checkRange && unit.gameObject != currentDemoCharacter) { return(unit); } } //after checking all units, return null return(null); }