Page 1 of 1

How to assign methods to OnSelectedUsable through script on Proximity Selector?

Posted: Tue Apr 19, 2022 11:28 pm
by GinMartini
Hello,

How do I assign methods from another gameobject to the proximity selector's OnSelectedUsable method?

I got this so far:

proximitySelector.onSelectedUsable.AddListener(

But then I'm completely lost. Is this even the right path to go down, or am I totally missing the right way to do this?

Thank you!

EDIT: Okay, as usual—the SECOND I post a question to a forum—I figure out a solution. For those wondering, here's what worked for me:

proximitySelector.onSelectedUsable.AddListener(delegate { someScript.someMethod(); });

I'd be curious to see if there's a better way to do this, or if there is some issue with the solution I found! Thanks again!

Re: How to assign methods to OnSelectedUsable through script on Proximity Selector?

Posted: Wed Apr 20, 2022 7:24 am
by Tony Li
Nope, AddListener() is the way to do it. If you want to access the Usable that got selected, you can do it similarly like this:

Code: Select all

proximitySelector.onSelectedUsable.AddListener((usable) => { SomeMethod(usable); });

Re: How to assign methods to OnSelectedUsable through script on Proximity Selector?

Posted: Thu Apr 21, 2022 2:01 pm
by GinMartini
Thank you! I appreciate the follow up!

Re: How to assign methods to OnSelectedUsable through script on Proximity Selector?

Posted: Thu Apr 21, 2022 3:40 pm
by Tony Li
Happy to help!