private void OnInteractFinish() { _interactingId = -1; var finishedBlock = InteractingBlock; InteractingBlock = null; finishedBlock.OnInteract(this); }
public void Update() { if (Health <= 0) { World.GameOver(); return; } if (transform.position.y < -5) { World.GameOver(); return; } var horizontal = Input.GetAxis("Horizontal") * rotateSpeed; var vertical = Input.GetAxis("Vertical") * moveSpeed; _animator.SetInteger(_animMove, vertical == 0 ? 0 : 1); Controller.Move( gameObject.transform.rotation * new Vector3(0, -9.8f * Time.deltaTime, vertical * Time.deltaTime) ); gameObject.transform.Rotate(new Vector3(0, horizontal, 0)); if (Stamina < MaxStamina && Time.time - _lastStaminaUse > TimeToStaminaFill) { if (Time.time - _lastStaminaHeal > 0.05f) { Stamina = Math.Min( MaxStamina, Stamina + staminaRegeneration ); _lastStaminaHeal = Time.time; } } for (var i = 0; i < 6; i++) { var key = keyMap[i]; if (!Input.GetKey(key)) { continue; } var item = Inventory.Get(i); item?.UseItem(this); } if (InteractingBlock) { // Cancel if key is no longer pressed, or player is too far if (Input.GetKey(KeyCode.Space) && InteractingBlock.CanInteract(this)) { return; } _statusManager.CancelItem(_interactingId); InteractingBlock = null; _interactingId = -1; } else { if (!Input.GetKey(KeyCode.Space)) { return; } // Start interaction var interactableBlock = GetInteractableBlock(); if (!interactableBlock) { return; } InteractingBlock = interactableBlock; InteractingBlock.OnStartInteract(this); _interactingId = _statusManager.AddProgress( InteractingBlock.GetInteractProgress(this), InteractingBlock.GetInteractDuration(this), OnInteractFinish ); } }