void Update() { if (!isServer || _gameFlow.isFinished || _health == 0f) { return; } Transform[] players = FindObjectsOfType <UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().Select(obj => obj.transform).ToArray(); bool isTouchingPlayer = false; Transform nearbyPlayer = GetPlayerToMoveTo(players, ref isTouchingPlayer); if (!_isMonster && nearbyPlayer) { _log.add("wakeup"); WakeUp(); } else if (_isMonster && !nearbyPlayer) { if (_lostPlayerTime == 0) { _lostPlayerTime = Time.time; } else if (Time.time - _lostPlayerTime < sleepTime) { _log.add("snooze"); Snooze(); } } if (_log != null && _lastPlayerHit && (!isTouchingPlayer || _lastPlayerHit != nearbyPlayer)) { string playerName = _lastPlayerHit.GetComponent <PlayerAvatar>().avatarName; _log.add($"{playerName}\tlost"); } if (_isMonster && nearbyPlayer) { Vector3 playerAnchor = new Vector3(nearbyPlayer.position.x, transform.position.y, nearbyPlayer.position.z); transform.LookAt(Vector3.Slerp(playerAnchor, transform.position + transform.forward, 1f - Time.deltaTime * turnSpeed)); transform.position = Vector3.MoveTowards(transform.position, playerAnchor, Time.deltaTime * moveSpeed * Mathf.Sqrt(_health)); if (isTouchingPlayer) { if (_log != null && _lastPlayerHit != nearbyPlayer) { string playerName = nearbyPlayer.GetComponent <PlayerAvatar>().avatarName; _log.add($"{playerName}\thit"); } _gameFlow.HitPlayer(nearbyPlayer, hitWeight); } } _lastPlayerHit = isTouchingPlayer ? nearbyPlayer : null; }