//Author: Ben Stern
    /// <summary>
    /// Attempt to trigger interactions on another object
    /// </summary>
    /// <param name="obj">the object whose interactions we are triggering</param>
    public bool AttemptInteraction(InteractableBase obj)
    {
        List <string> possibleInteractions = GetPossibleInteractions(obj);

        possibleInteractions.AddRange(obj.GetPossibleInteractions(this));
        if (possibleInteractions.Count == 0)
        {
            Debug.Log("NO Interactions, send message to UI");
        }
        else if (possibleInteractions.Count == 1)
        {
            obj.Interact(possibleInteractions[0], this);
            //Debug.Log(possibleInteractions[0]);
            return(true);
        }

        // Author: John Vance
        // Purpose: Used for multiple interactions between objects
        else
        {
            // Display dropdown menu and sets it to the second selected object's position
            interactionDropdown.transform.position = this.transform.position + new Vector3(0.0f, 50.0f, 0.0f);
            interactionDropdown.SetActive(true);

            // Clears out all of the options so that the interactions for the new item are used
            drop.ClearOptions();

            // Populates the dropdown with the current interactions
            drop.options.Add(new Dropdown.OptionData()
            {
                text = "Exit " + this.name
            });
            drop.AddOptions(possibleInteractions);

            // Sets up the "title"
            drop.options.Insert(0, new Dropdown.OptionData(title));
            drop.value            = 0;
            drop.captionText.text = title;

            // When something is selected in the dropdown menu it runs the below code
            drop.onValueChanged.AddListener(delegate
            {
                if (drop.value == 0 || drop.value == 1)
                {
                    interactionDropdown.SetActive(false);
                }
                else
                {
                    obj.Interact(possibleInteractions[drop.value - 2], this);
                    interactionDropdown.SetActive(false);
                }

                // Allows for other objects to use the listener
                drop.onValueChanged.RemoveAllListeners();
            });

            return(true);
        }
        return(false);
    }
示例#2
0
 /// <summary>
 /// This function is called when the player presses the interact button
 /// If the player is standing close to an interactable object, he will
 /// call the interact function of that object
 /// </summary>
 public void Interact()
 {
     if (interactable != null && controller.isGrounded == true)
     {
         interactable.Interact();
         velocity.x = 0;
     }
 }
示例#3
0
    //Author: Ben Stern
    /// <summary>
    /// Attempt to empty the item in this container into something else
    /// </summary>
    /// <param name="itemToEmptyInto">an interactable Item containing</param>
    public void EmptyInto(InteractableBase itemToEmptyInto)
    {
        bool completed = false;

        for (int i = 0; i < itemsHolding.Count; i++)
        {
            itemToEmptyInto.Interact("Place Item", itemsHolding[i]);

            // Allows for the spatula to move onto the frying pan and plate
            itemToEmptyInto.Interact("Take Egg", interactableComponent);

            itemToEmptyInto.Interact("Place On Plate", itemsHolding[i]);

            //double check that the item is no longer in this container befor editing properties.
            if (itemsHolding[i].transform.parent != transform)
            {
                itemsHolding.RemoveAt(i);
                i--;
                completed = true;
                continue;
            }
            completed = false;
        }

        if (completed)
        {
            //remove the empty into interaction from the list
            interactableComponent.RemoveInteractionFromList("Empty into");
        }

        if (HoldingWater)
        {
            if (itemToEmptyInto.gameObject.name == "Strainer")
            {
                itemToEmptyInto.Interact("Empty water", interactableComponent);
            }

            else
            {
                itemToEmptyInto.Interact("Fill water", interactableComponent);

                EmptyWater();
            }
        }
    }
 private bool TryAttack()
 {
     if (m_LastTimeShot + delayBetweenAttacks * m_cdr < Time.time)
     {
         m_FocusedPlayer.Interact(gameObject);
         m_LastTimeShot = Time.time;
         return(true);
     }
     return(false);
 }
示例#5
0
 private bool TryBasicAttack()
 {
     if (m_LastTimeBasic + m_DelayBetweenAttacks * m_cdr < Time.time)
     {
         m_PlayerInteractable.Interact(selfGameObject);
         m_LastTimeBasic = Time.time;
         m_GFX.SetActive(true);
         return(true);
     }
     return(false);
 }
示例#6
0
    //author: Ben Stern
    /// <summary>
    /// Place an item into this container
    /// </summary>
    /// <param name="itemToHold">The item to place into the container</param>
    public void HoldItem(InteractableBase itemToHold)
    {
        itemsHolding.Add(itemToHold);
        //move the item into the container
        itemToHold.transform.position = transform.position + PlacePositionRelative;
        itemToHold.transform.SetParent(transform);
        //call any interaction that happen when this item is placed in a container
        itemToHold.Interact("On Place In Container", interactableComponent);
        //objects in containers should not be selectable until taken out of the container
        itemToHold.GetComponent <SelectableObject>().enabled = false;

        //add the empty into to interaction to the list
        interactableComponent.AddInteractionToList("Empty into", EmptyInto);
    }
    //Author: John Vance, Ben Stern
    /// <summary>
    /// Attempt to empty the item in this container into something else
    /// </summary>
    /// <param name="itemToEmptyInto">an interactable Item containing</param>
    public void EmptyInto(InteractableBase itemToEmptyInto)
    {
        // Allows for the spatula to move onto the frying pan and plate
        itemToEmptyInto.Interact("Take Egg", interactableComponent);


        //double check that the item is no longer in this container befor editing properties.
        if (currentContainer.transform.parent != transform)
        {
            currentContainer = null;
            //remove the empty into interaction from the list
            interactableComponent.RemoveInteractionFromList("Empty into");
        }
    }
示例#8
0
 protected void Interacting()
 {
     if (interactTarget != null)
     {
         interactTarget?.Interact(this);
         if (interactTarget.GetComponent <HyperSeed>() != null)
         {
             _animator.SetBool("getHyperSeedAni", true);
         }
         else if (interactTarget.GetComponent <OreVein>() != null)
         {
             _animator.SetBool("getAmmoAni", true);
         }
         interactTarget = null;
         lastInteract   = Time.fixedTime;
     }
     currentState = PlayerState.Neutral;
 }
示例#9
0
 void HandleInteractionMovement()
 {
     if (focus != null)
     {
         float minDistance = focus.radius * .8f;
         if (Vector3.Distance(focus.transform.position, m_NavAgent.transform.position) < minDistance)
         {
             focus.Interact(gameObject);
             RemoveFocus();
         }
         else
         {
             m_NavAgent.enabled          = true;
             m_NavAgent.updatePosition   = true;
             m_NavAgent.updateRotation   = true;
             m_NavAgent.isStopped        = false;
             m_NavAgent.stoppingDistance = 0;
             bool result = m_NavAgent.SetDestination(focus.transform.position);
         }
     }
 }