Exemplo n.º 1
0
        public void Interact()
        {
            _previousState = _currentState;
            _currentState  = Mouse.GetState();
            if (_focus != null)
            {
                float distance = Vector2.Distance(_position, _focus.GetPosition());
                if (distance > interactRad)
                {
                    // If player is too far from the Interactable Object (ie. ShipComponent)
                    // then cancel current action and reset focus to a null value to prevent it from being interacted again from a distance
                    _focus.Cancel();
                    _focus = null;
                    _fixProgress.SetActive(false);
                    return;
                }

                BreakableComponent b = _focus as BreakableComponent;

                if (_currentState.LeftButton == ButtonState.Released && _previousState.LeftButton == ButtonState.Pressed)
                {
                    if (b != null)
                    {
                        if (b.IsBroken())
                        {
                            Item item = _inventory.items.Find(i => i.itemType == b.GetRequiredItem());
                            if (item == null)
                            {
                                return;
                            }
                            _fixProgress.SetActive(true);
                        }
                    }
                    _focus.Interact();
                }

                if (b != null)
                {
                    _fixProgress.UpdateProgress(b.GetFixProgress());
                }
            }
        }
Exemplo n.º 2
0
    void UpdatePlayer()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Interact();
        }

        // If Player is interacting with a ShipComponent object
        if (focus)
        {
            BreakableComponent breakable = focus.GetComponent <BreakableComponent>();
            if (breakable)
            {
                float progress = breakable.GetProgress();
                progressBar.SetProgress(progress);
            }

            // Check if it's too far away and cancel current progress
            if (Vector2.Distance(focus.transform.position, transform.position) > 1f)
            {
                if (breakable)
                {
                    progressBar.SetProgress(0f);
                    progressBar.gameObject.SetActive(false);
                }
                focus.Cancel();
                focus = null;
            }
        }

        if (!o2Active)
        {
            o2Current -= o2Multiplier * Time.deltaTime;
        }
        o2Bar.SetProgress(o2Current / o2TotalCapacity);
    }