// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!witchLogic.audioSource.isPlaying && !hasPlayedSound) { hasPlayedSound = true; playChasingSound(targetPlayer.tag); } // continue chasing after player Vector3 targetPosition = new Vector3(targetPlayer.position.x, animator.transform.position.y, targetPlayer.position.z); Vector3 direction = animator.transform.position; direction.y = 0f; animator.transform.LookAt(targetPosition); //Quaternion.Slerp(animator.transform.rotation, Quaternion.LookRotation(direction), 0.1f); animator.transform.position = Vector3.MoveTowards(animator.transform.position, targetPosition, speed * Time.deltaTime); if (targetPlayer.GetComponent <PlayerLogic>().isHidden()) // to indicate a player is hidden { targetPlayer.GetComponent <PlayerLogic>().stopChasingMe(); witchLogic.playSound(witchLogic.complaningSound); } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // play laughing sound only when she hasn't laughed before and no other phrase is playing if (!witchLogic.audioSource.isPlaying && !hasPlayedSound) { hasPlayedSound = true; witchLogic.playSound(witchLogic.laughSound); } playerPower = targetPlayer.GetComponentInChildren <CameraShake>().getPower(); /*if (animator.transform.position.x != targetPlayer.position.x && animator.transform.position.z != targetPlayer.position.z) * { * centerOnPlayer(targetPlayer, animator); * }*/ if (Mathf.Abs(animator.transform.position.x - targetPlayer.position.x) >= 0.01f && Mathf.Abs(animator.transform.position.z - targetPlayer.position.z) >= 0.01f) { Debug.Log("difference x: " + Mathf.Abs(animator.transform.position.x - targetPlayer.position.x)); Debug.Log("difference z: " + Mathf.Abs(animator.transform.position.z - targetPlayer.position.z)); centerOnPlayer(targetPlayer, animator); } else { if (!canPlayerResist) { Debug.Log("last difference x: " + Mathf.Abs(animator.transform.position.x - targetPlayer.position.x)); Debug.Log("last difference z: " + Mathf.Abs(animator.transform.position.z - targetPlayer.position.z)); targetPlayer.GetComponent <PlayerLogic>().playSound(targetPlayer.GetComponent <PlayerLogic>().caughtSound); targetPlayer.GetComponent <Animator>().SetBool("isCaught", true); targetPlayer.GetComponent <Animator>().SetBool("isIdle", false); targetPlayer.GetComponent <Animator>().SetBool("isWalking", false); targetPlayer.GetComponent <Animator>().SetBool("isRunning", false); canPlayerResist = true; targetPlayer.GetComponentInChildren <CameraShake>().setCanShake(true); if (targetPlayer.GetComponent <PlayerLogic>().getFruitCounter() > 0) { // activate prompt message gameManager.activateResistanceSlider(targetPlayer); targetPlayer.GetComponent <PlayerController>().getGamePadController().SetVibration(motorIndex, motorLevel); } } } if (canPlayerResist && !freePlayer) { // start decremeanting fruits slowly dropTimer -= Time.deltaTime; if (goal >= 1f) { targetPlayer.GetComponentInChildren <CameraShake>().setResistanceMeter(playerPower / goal); } else { targetPlayer.GetComponentInChildren <CameraShake>().setResistanceMeter(0f); } if (dropTimer < Mathf.Epsilon) { if (targetPlayer.GetComponent <PlayerLogic>().getFruitCounter() != 0) { targetPlayer.GetComponent <PlayerLogic>().loseFruits(fruitLossRate, false); } dropTimer = fruitDropTime; } if (targetPlayer.GetComponent <PlayerLogic>().getFruitCounter() == 0 || playerPower >= goal) { targetPlayer.GetComponentInChildren <CameraShake>().setCanShake(false); // animator.setBool("isIdle", true); is set in waitScript waitScript.DoCoroutine(waitTime); freePlayer = true; targetPlayer.GetComponent <PlayerController>().getGamePadController().StopVibration(); } } }