Page 1 of 1

Proximity Selector Priority (UI)

Posted: Tue Sep 20, 2022 12:22 am
by cptscrimshaw
Hi Tony,

I have a subclass of ProximitySelector that accounts for priority when choosing which usable to use when you hit the button, but I'm having trouble getting the correct UI to show. For example, if I walk up to two objects that both have usables, it will choose the correct one when I hit the button, but the UI is showing text for another one. I was trying to override the SetCurrentUsable method, but running into troubles. Is this something you've accounted for before?

Thanks so much!

Re: Proximity Selector Priority (UI)

Posted: Tue Sep 20, 2022 11:18 am
by Tony Li
Hi,

In your overridden class, call CheckTriggerEnter(GameObject) to set the usable. This will make it act like the usable just entered the Proximity Selector and should be made the current usable.

Re: Proximity Selector Priority (UI)

Posted: Tue Sep 20, 2022 11:30 am
by cptscrimshaw
Hi Tony,

Thanks - let me try to explain a bit further. My current overridden class is for UseCurrentSelection(), so that only gets called when the player presses the button to activate the usable. I'd like to be able to update the ProximitySelector on trigger enter and check the priority of all usablesinrange and show the one with the highest priority.

Re: Proximity Selector Priority (UI)

Posted: Tue Sep 20, 2022 1:53 pm
by Tony Li
What about just overriding the CheckTriggerEnter() method then? If the usable that's passed to CheckTriggerEnter() is higher priority than the current usable, call base.CheckTriggerEnter(); otherwise add it (usablesInRange.Add(usable);) but don't call OnSelectedUsableObject(usable);.

Re: Proximity Selector Priority (UI)

Posted: Tue Sep 20, 2022 8:56 pm
by cptscrimshaw
Thanks Tony!

That worked, but I did have to add a check to make sure that currentUsable wasn't null. And adding the usable didn't seem to matter, though I haven't tested it a ton.

Code: Select all

        protected override void CheckTriggerEnter(GameObject other)
        {
            if(other.GetComponent<UsableES>() != null)
            {
                if(currentUsable == null)
                {
                    base.CheckTriggerEnter(other);
                }
                else
                {
                    if(other.GetComponent<UsableES>().priority > currentUsable.GetComponent<UsableES>().priority)
                    {
                        base.CheckTriggerEnter(other);
                    }
                }
            }
        }

Re: Proximity Selector Priority (UI)

Posted: Tue Sep 20, 2022 9:14 pm
by Tony Li
Glad to help!