[HOWTO] How To: Not Select Usable If Conditions Are False
Posted: Wed May 17, 2023 12:48 pm
Since the Selector/Usable system can be used for anything, not just Dialogue System Triggers, it doesn't natively check if the NPC's Dialogue System Trigger > Conditions are valid. If you want to do this so that it prevents the Selector/Proximity Selector from selecting a Usable whose Dialogue System Trigger > Conditions are false, you can make a subclass. Example:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class MyProximitySelector : ProximitySelector
{
protected override void CheckTriggerEnter(GameObject other)
{
if (!enabled || other == null) return;
var usable = other.GetComponent<Usable>();
if (usable == null || !usable.enabled) return;
var dsTrigger = other.GetComponent<DialogueSystemTrigger>();
if (dsTrigger != null && !(dsTrigger.enabled && dsTrigger.condition.IsTrue(transform))) return;
base.CheckTriggerEnter(other);
}
{/code]