// Update is called once per frame void Update() { if (stunComponent.IsStun()) { return; } if (!isDead) { agent.enabled = true; if (Vector3.Distance(agent.destination, playerObj.transform.position) > 1.0f) { agent.destination = playerObj.transform.position; } } }
// Update is called once per frame void FixedUpdate() { if (StunComponent && StunComponent.IsStun()) { return; } float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); if (isInAir) { GetComponent <Rigidbody>().AddForce(Vector3.right * horizontalInput * moveMaxSpeed * jumpSpeedRatio, ForceMode.Force); GetComponent <Rigidbody>().AddForce(Vector3.forward * verticalInput * moveMaxSpeed * jumpSpeedRatio, ForceMode.Force); } else { GetComponent <Rigidbody>().AddForce(Vector3.right * horizontalInput * moveMaxSpeed, ForceMode.Force); GetComponent <Rigidbody>().AddForce(Vector3.forward * verticalInput * moveMaxSpeed, ForceMode.Force); } Vector3 targetDirection = (Vector3.right * horizontalInput + Vector3.forward * verticalInput).normalized; if (targetDirection.magnitude > 0.0f) { Quaternion targetRotation = Quaternion.LookRotation(targetDirection); transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed); } if (Input.GetKey("space") && !isInAir) { GetComponent <Rigidbody>().AddForce(Vector3.up * jumpHeight, ForceMode.Impulse); isInAir = true; } }