Obtain Usable Information

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Obtain Usable Information

Post by PayasoPrince »

Hello,

I would like to add a new OnSelectedUsableI() event to my selector. I would like to get the gameobject that is currently selected and store it into a gameobject.

Is there a method already created that I can use to reference the usable object that is currently selected or will I just need to create new OnTriggerEnter/Exit methods?

Code: Select all

gameobject usableObject;

OnSelectedUsable()
{

usableObject = This is where I would need a method that references the usable that is selected.

}
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Obtain Usable Information

Post by Tony Li »

Hi,

The ProximitySelector (and Selector) component has a UnityEvent OnSelectedUsable() and a C# event SelectedUsableObject. You can add a script to the ProximitySelector's GameObject that hooks into the C# event. Example:

Code: Select all

public class LogSelectionInfo : MonoBehaviour
{
    private Usable currentSelection = null;
    
    void Awake()
    {
        var proximitySelector = GetComponent<ProximitySelector>();
        proximitySelector.SelectedUsableObject += OnSelectedUsableObject;
        proximitySelector.DeselectedUsableObject += OnDeselectedUsableObject;
    }
    
    void OnSelectedUsableObject(Usable usable)
    {
        currentSelection = usable;
    }
    
    void OnDeselectedUsableObject(Usable usable)
    {
        currentSelection = null;
    }
}
ProximitySelector API reference
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Obtain Usable Information

Post by PayasoPrince »

I was setting it up the way you provided but actually found a simpler way.

My PlayerController already had a reference to it's attached ProximitySelector. So, I was able to call ProximitySelector.CurrentUsable and it seems to work fine! :mrgreen:
Post Reply