private void Update()
        {
            if (currentInteractible != null)
            {
                if (closestIndicatorSprite != null)
                {
                    closestIndicatorSprite.enabled = false;
                }

                return;
            }

            if (interactibles.Count > 0)
            {
                PhysicalInteractible interactible = GetClosest();

                if (closestInteractible != interactible)
                {
                    UpdateCurrentInteractible(interactible);
                    UpdateCurrentIndicator();
                }

                UpdateIndicatorVisibility();
            }
        }
 public static void AddInteractible(PhysicalInteractible interactible)
 {
     if (!interactibles.Contains(interactible))
     {
         interactibles.Add(interactible);
     }
 }
 /// <summary>
 /// Remove the current interactible.
 /// </summary>
 private static void RemoveCurrentInteractible()
 {
     if (closestIndicator != null)
     {
         closestInteractible       = null;
         closestInteractibleSprite = null;
     }
 }
 public static void RemoveInteractible(PhysicalInteractible interactible)
 {
     interactibles.Remove(interactible);
     if (interactibles.Count == 0)
     {
         RemoveCurrentInteractible();
         RemoveCurrentIndicator();
     }
 }
        /// <summary>
        /// Retrieves the closest interactible object that the player is close enough to interact with.
        /// </summary>
        /// <returns>The closest interactible object.</returns>
        private PhysicalInteractible GetClosest()
        {
            if (interactibles.Count == 0)
            {
                return(null);
            }

            PhysicalInteractible closest = interactibles[0];
            float closestDist            = DistanceFromPlayer(closest);

            foreach (PhysicalInteractible next in interactibles)
            {
                float dist = DistanceFromPlayer(next);
                if (dist < closestDist)
                {
                    closest     = next;
                    closestDist = dist;
                }
            }

            return(closest);
        }
 /// <summary>
 /// Remove an object from the list of objects the player is close enough to interact with.
 /// </summary>
 /// <param name="interactible">The object to remove.</param>
 void IInteractionComponent.RemoveInteractible(PhysicalInteractible interactible) => InteractionComponent.RemoveInteractible(interactible);
 /// <summary>
 /// Add an object to the list of objects the player is close enough to interact with.
 /// </summary>
 /// <param name="interactible">The object to add.</param>
 void IInteractionComponent.AddInteractible(PhysicalInteractible interactible) => InteractionComponent.AddInteractible(interactible);
 /// <summary>
 /// Set information about the current interactible.
 /// </summary>
 /// <param name="interactible">The interactible to set.</param>
 private void SetCurrentInteractible(PhysicalInteractible interactible)
 {
     closestInteractible       = interactible;
     closestInteractibleSprite = closestInteractible.GetComponent <SpriteRenderer>();
 }
 /// <summary>
 /// Update the current interactible information.
 /// </summary>
 /// <param name="interactible">The interactible to set.</param>
 private void UpdateCurrentInteractible(PhysicalInteractible interactible)
 {
     RemoveCurrentInteractible();
     SetCurrentInteractible(interactible);
 }
 /// <summary>
 /// How far away an interactible is from the player.
 /// </summary>
 /// <param name="interactible">The interactible to check.</param>
 /// <returns>The distance from the center of the player to the center of the
 /// interactible.</returns>
 private float DistanceFromPlayer(PhysicalInteractible interactible)
 {
     return((interactible.Center - (Vector2)playerCollider.bounds.center).magnitude);
 }
Esempio n. 11
0
        /// <summary>
        /// Whether or not the player can carry this game object.
        /// </summary>
        /// <param name="obj">The object to check.</param>
        /// <returns>True if the object can be carried. False otherwise.</returns>
        public bool CanCarry(GameObject obj)
        {
            PhysicalInteractible interactible = obj.GetComponent <PhysicalInteractible>();

            return((interactible != null) && (interactible is Carriable));
        }
Esempio n. 12
0
 /// <summary>
 /// Remove an object from the list of objects the player is close enough to interact with.
 /// </summary>
 /// <param name="interactible">The object to remove.</param>
 public void RemoveInteractible(PhysicalInteractible interactible) => Interaction.RemoveInteractible(interactible);
Esempio n. 13
0
 /// <summary>
 /// Add an object to the list of objects the player is close enough to interact with.
 /// </summary>
 /// <param name="interactible">The object to add.</param>
 public void AddInteractible(PhysicalInteractible interactible) => Interaction.AddInteractible(interactible);