Ejemplo n.º 1
0
    private void FixedUpdate()
    {
        var hit = Physics2D.CircleCast(transform.position, interactionRange,
                                       Vector2.zero, Mathf.Infinity, interactables);

        currentTarget = hit.collider?.GetComponent <InteractionTarget>();

        if (currentTarget != lastTarget)
        {
            if (currentTarget != null)
            {
                Debug.Log($"[{currentTarget.ActionDisplay}] {currentTarget.gameObject.name}");

                currentTarget.ActionDisplayChanged += ActionDisplayChanged;
                currentTarget.EnterRange(this);
            }
            else
            {
                Debug.Log($"Moved out of interaction range.");

                if (lastTarget != null)
                {
                    lastTarget.ExitRange(this);
                    lastTarget.ActionDisplayChanged -= ActionDisplayChanged;
                }
            }

            InteractionTargetChanged?.Invoke(currentTarget);
        }

        lastTarget = currentTarget;
    }