I'm trying to achieve the same thing that was mentioned in the original post.
In particular, I was wondering if you could explain this:
If you want to restrict mouse clicks further so they only interact if you click on the NPC, you can make a subclass of ProximitySelector and override the UseCurrentSelection() method to check if the mouse is over the NPC. If so, call the base.UseCurrentSelection() method.
Sorry, I'm not great at coding yet, so it's hard for me to follow.
using UnityEngine;
using PixelCrushers;
using PixelCrushers.DialogueSystem;
public class ProximitySelectorWithMouseOver : ProximitySelector
{
public LayerMask mouseCheckLayerMask = 1; // Default layer.
public Selector.Dimension dimension = Selector.Dimension.In3D;
protected override bool IsUseButtonDown()
{
return base.IsUseButtonDown() && IsMouseOverUsable();
}
private bool IsMouseOverUsable()
{
if (currentUsable == null) return false;
#if !USE_NEW_INPUT
// Return false if mouse is over a UI element:
// (In new Input System, IsPointerOverGameObject returns true for all GameObjects,
// not just UI objects, so skip this check until Input System is fixed.)
if (UnityEngine.EventSystems.EventSystem.current != null && UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) return false;
#endif
var mousePosition = InputDeviceManager.GetMousePosition();
switch (dimension)
{
default:
case Selector.Dimension.In3D:
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity, mouseCheckLayerMask))
{
if (hit.collider.gameObject == currentUsable.gameObject) return true;
}
return false;
case Selector.Dimension.In2D:
RaycastHit2D hit2D;
hit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(mousePosition), Vector2.zero, Mathf.Infinity, mouseCheckLayerMask);
if (hit2D.collider != null)
{
if (hit2D.collider.gameObject == currentUsable.gameObject) return true;
}
return false;
}
}
}
If your game is in 2D, change the Dimension dropdown at the bottom to In 2D.
If your Usable NPC isn't on the Default layer, add its layer to the Mouse Check Layer Mask dropdown.