private void Update() { RaycastHit hit; var direction = (PlayerEyes.GetWorldLocation() - _fireSocket.transform.position).normalized; if (Physics.Raycast(new Ray(_fireSocket.transform.position, direction), out hit)) { _targetAimObject.transform.position = hit.point + hit.normal * 0.001f; _targetAimObject.transform.rotation = Quaternion.LookRotation(hit.normal); var command = hit.collider.GetComponentInParent <NPCCommandable>(); if (_commandInProgress && command != _commandInProgress) { _commandInProgress.SetFillAmount(0.0f); _progressAmount = 0.0f; } if (command) { _progressAmount = Mathf.MoveTowards(_progressAmount, 1.0f, Time.deltaTime * _fillAmountSpeed); command.SetFillAmount(_progressAmount); _commandInProgress = command; } if (Math.Abs(_progressAmount - 1.0f) < float.Epsilon) { CommandManager.Instance.CompleteProgress(_commandInProgress); _audioSource.time = 0.5f; _audioSource.Play(); } } }
public void CompleteProgress(NPCCommandable commandable) { if (commandable is NPCCommand && NpcControlled != (NPCCommand)commandable) { if (NpcControlled) { NpcControlled.UnCommand(); } NpcControlled = (NPCCommand)commandable; _controlledNpcChanged?.Invoke(NpcControlled); NpcControlled.Command(); } if (commandable is NPCPressurePlate && NpcControlled != (NPCPressurePlate)commandable) { if (PressurePlateController) { PressurePlateController.UnCommand(); } PressurePlateController = (NPCPressurePlate)commandable; _controlledPressurePlateChanged?.Invoke(PressurePlateController); PressurePlateController.Command(); } }