public override bool DetectRadius() { // Clear the objects in range if (ObjectsInRange.Count > 0) { ObjectsInRange.Clear(); } // If it detects any objects in it's radius if (base.DetectRadius()) { // if both are in the list at the same time // check if they are both within range to chase the cat if (ObjectsInRange.Contains(playerObject) && ObjectsInRange.Contains(kittenObject)) { DIRECTIONS playerDirection = GetTargetDirection(playerObject.transform.position); DIRECTIONS kittenDirection = GetTargetDirection(kittenObject.transform.position); // if both are clear // then both can chase the cat if (CheckIfClear(playerDirection, playerObject.transform.position) && CheckIfClear(kittenDirection, kittenObject.transform.position)) { // set the kitten object as the target // it should prioritise the kitten targetObject = kittenObject; targetDir = GetTargetDirection(); // is shocked should only trigger once // to stop it from repeating multiple times if (isTrapped == false) { isShocked = true; TrappedTilePosition = MapManager.Instance.GetWorldToTilePos(transform.position); } if (m_ShockUI != null) { m_ShockUI.gameObject.SetActive(true); } isTrapped = true; } else { isTrapped = false; } } else { isTrapped = false; } // if it is trapped, it shouldnt be able to do anything else if (isTrapped) { return(false); } //// If it already has a target that it is running from //if (targetObject != null) // return false; // Loop through the detected objects string successfulTag = ""; foreach (GameObject detectedObj in ObjectsInRange) { // It will only look for these two objects if (detectedObj.tag == "Player" || detectedObj.tag == "Kitten") { // Only detect when its idle if (characterState == STATE.IDLE) { //THIS IS A HACK, STORE PREV DATA GameObject PREVtargetObject = targetObject; DIRECTIONS prevTargetDir = targetDir; // Get the target object targetObject = detectedObj; // Check for the target direction targetDir = GetTargetDirection(); // Check if the path to the detected object is clear if (CheckIfClear(targetDir, targetObject.transform.position) == false) { // that target isnt available a danger to the mouse if (successfulTag == "") //if theres nothing just reset { StopMovement(); } //reset the data targetObject = PREVtargetObject; targetDir = prevTargetDir; // check the next if there is continue; } isShocked = true; if (detectedObj.tag == "Kitten") { if (m_ShockUI != null) { m_ShockUI.gameObject.SetActive(true); } } else { elapsedTime = 0.0f; } ////HACK PRIROTIZE KITTEN //if (successfulTag == "Kitten" && detectedObj.tag == "Player") //{ // targetObject = PREVtargetObject; // targetDir = prevTargetDir; //} //else //{ // // reset it if it tracks the player // if (detectedObj.tag == "Player") // elapsedTime = 0.0f; //} // Debug.Log("Mouse IsShocked Changed in line 197" + isShocked); successfulTag = detectedObj.tag; } // if it is a running state when it detects a enemy else if (characterState == STATE.RUNNING) { // if it detects a new enemy while running from the player if (detectedObj != targetObject && targetObject.tag == "Player") { DIRECTIONS detectedObjDir = GetTargetDirection(detectedObj.transform.position); // if the object detected is behind a wall // skip this object because it's not a threat if (CheckIfClear(detectedObjDir, detectedObj.transform.position) == false) { continue; } // it has to be shocked isShocked = true; // Debug.Log("Mouse IsShocked Changed in line 219" + isShocked); StartCoroutine(PlayerShockUITime()); StopMovement(); mouseMovement.StopMovement(); mouseMovement.ResetMovementList(); } } } // If it spots the player or kitten // it will try to run away //if (detectedObj.tag == "Player" || detectedObj.tag == "Kitten" ) //{ // // if it already has a target // if (targetObject != null) // { // // If it detects the kitten while being chased by the player // if (targetObject != detectedObj && targetObject.tag == "Player") // { // // Make it shocked // isShocked = true; // // stop both the movement // StopMovement(); // mouseMovement.StopMovement(); // mouseMovement.ResetMovementList(); // } // } // // Set the player object as it's current target // targetObject = detectedObj; // targetDir = GetTargetDirection(); // // Check the direction if its clear // // if it isn't then they detected an enemy through the wall // //if (CheckIfClear(targetDir) == false && targetObject.tag != "Player") // //{ // // if (characterState == STATE.RUNNING) // // { // // mouseMovement.ResetMovementList(); // // mouseMovement.StopMovement(); // // } // // StopMovement(); // // continue; // //} // // shocked // if (characterState != STATE.RUNNING) // isShocked = true; //} } //if (isShocked && characterState == STATE.IDLE) //{ // if (targetObject.tag == "Player") // StartCoroutine(PlayerShockUITime()); //} } else { isShocked = false; } //else //{ // characterState = STATE.IDLE; // targetObject = null; // targetDir = DIRECTIONS.NONE; //} return(false); }