// returns the index of a random sheep that can move // places the sheep itself into the sheep variable private int randomSheepWithMoves(out SheepController sheep) { int numSheep = gameManager.sheep.Length; SheepController shController; SquareController sqController; SheepController match = null; float matched = 0; int returnIndex = 0; for (int i = 0; i < gameManager.sheep.Length; i++) { SheepController sh = gameManager.sheep[i]; shController = sh.GetComponent <SheepController>(); sqController = shController.Square().GetComponent <SquareController>(); if (sqController.PossibleSheepMoves().Count == 0) { continue; } matched++; if (Random.value < (1.0f / matched)) { returnIndex = i; match = sh; } } sheep = match.GetComponent <SheepController>(); return(returnIndex); }
private void CheckForCollisions() { Collider[] hitColliders = Physics.OverlapBox(gameObject.transform.position, transform.localScale / 2, Quaternion.identity); int i = 0; while (i < hitColliders.Length) { if (hitColliders[i].GetComponent <SheepController>()) { SheepController sc = hitColliders[i].GetComponent <SheepController>(); sc.onDeathPartcileSystemTransform.parent = null; sc.onDeathPartcileSystem.Play(); sc.gameObject.SetActive(false); sc.transform.position = new Vector3(1000, 1000, 1000); sc.GetComponent <NavMeshAgent>().Warp(new Vector3(1000, 1000, 1000)); LevelController.Instance.SheepReachedGoal(); } i++; } }