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; }
// server-side public void respawn() { if (_log != null) { _log.add("respawned"); } Invoke("RestoreProps", 1.5f); RpcRespawn(); }
// internal methods // server-side void End() { if (!isServer) { return; } if (_logGeneral != null) { _logGeneral.add("finished"); } RpcLightsOn(); RpcEndGame(); }
void HandleLog(string logString, string stackTrace, LogType type) { if (type == LogType.Error || type == LogType.Exception) { if (_logErrors != null) { _logErrors.add(logString); } Debug.Log($"ERROR: {logString} [{stackTrace}]"); } /* * else * { * _debug.print(logString); * }*/ }