//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); }