public void UpdateHealth() { if (!IsInfected) { if (_health < MaxHealth && (Time.time - _lastInfectedTime >= _healthRegenerationWaitTime)) { if (_isInitializing) { _health += _initialRegenerationRate; } else { _health += _healthRegenerationRate; } if (_health >= MaxHealth) { _health = MaxHealth; if (InfectionAudioSource && InfectionAudioSource.isPlaying) { InfectionAudioSource.Stop(); } if (_isInitializing) { TutorialManager.Instance.BroadcastTutorialAction("initialized"); _isInitializing = false; } } } if (_health <= (MaxHealth / 2.5f)) { float newSpeedModifier = StaticTools.Remap(_health, 0, MaxHealth, 0, 1); _firstPersonController.ModifySpeed(newSpeedModifier / _oldSpeedModifier); _oldSpeedModifier = newSpeedModifier; } else { _firstPersonController.ModifySpeed(1 / _oldSpeedModifier); _oldSpeedModifier = 1; } if (_health < MaxHealth) { if (InfectionAudioSource && !InfectionAudioSource.isPlaying) { InfectionAudioSource.time = 4.5f; InfectionAudioSource.Play(); } } if (InfectionAudioSource) { InfectionAudioSource.volume = StaticTools.Remap(_health, 0, MaxHealth, 0.6f, 0.3f); } } }
void UpdateGlitchness() { _glitchness = StaticTools.Remap(_health, 0, MaxHealth, MaxGlitchness, 0); _glitchEffect.intensity = _glitchness + DefaultGlitchIntensity; _glitchEffect.colorIntensity = _glitchness; _glitchEffect.flipIntensity = _glitchness + ((Time.timeScale > 0) ? DefaultGlitchIntensity : 0f); }
public void Update(Guard owner) { StateData stateData = owner.ChaseStateData; bool targetOnSight = false, targetAudible = false; if (owner.IsObjectInSight(stateData.TargetTransform.gameObject)) { targetOnSight = true; stateData.LastKnownPosition = stateData.TargetTransform.position; } else { AudibleObject targetAudibleObject = stateData.TargetTransform.GetComponent <AudibleObject>(); if (targetAudibleObject != null) { Vector3?targetLocation = owner.LocateObjectFromNoise(targetAudibleObject); if (targetLocation != null) { targetAudible = true; stateData.LastKnownPosition = targetLocation.Value; } } } if (targetOnSight) { Player player = stateData.TargetTransform.GetComponent <Player>(); if (player != null && !player.IsInfected) { float distance = Vector3.Distance(owner.transform.position, stateData.TargetTransform.position); if (distance <= owner.MaxInfectionRadius) { float infectionValue = StaticTools.Remap(distance, 0, owner.MaxInfectionRadius, owner.MaxInfection, 0); player.Infect(infectionValue); } } } if (Vector3.Distance(owner.transform.position, stateData.LastKnownPosition) > owner.LostDistance) { owner.MoveTowards(stateData.LastKnownPosition); /*if (!owner.MoveTowards(stateData.LastKnownPosition)) * { * StateMachine<Guard> stateMachine = owner.GetStateMachine(); * stateMachine.SwitchState(stateMachine.GetPreviousState() ?? GuardStates.Idle.Instance); * }*/ } else { if (!targetOnSight && !targetAudible) { // Lost target StateMachine <Guard> stateMachine = owner.GetStateMachine(); stateMachine.SwitchState(stateMachine.GetPreviousState() ?? GuardStates.Idle.Instance); } else { // Too Close to target owner.StopMoving(); Vector3 lookAtPos = stateData.TargetTransform.position; lookAtPos.y = owner.transform.position.y; owner.transform.LookAt(lookAtPos); //TODO: Switch state or do something } } }