Page 3 of 3

Re: Questions for operating with mouse only

Posted: Mon Sep 30, 2024 2:08 am
by gaku2_sigehiro
I tried the sample.
It's amazing. This is the behavior I was looking for.
This allows you to create the behavior you want.
Thank you for creating the script.

Re: Questions for operating with mouse only

Posted: Mon Sep 30, 2024 8:42 am
by Tony Li
Happy to help!

For future readers who want to use the script without having to download the unitypackage, it's here:

Code: Select all

using UnityEngine;
using PixelCrushers;
using PixelCrushers.DialogueSystem;

public class ProximitySelectorWithMouseDetection : ProximitySelector
{
    public float maxSelectionDistance = 999f;
    public LayerMask layerMask = 1; // Default

    private RaycastHit[] hits = new RaycastHit[10];

    // Run raycast to mouse cursor to make sure it's on Usable object:
    protected override bool IsUseButtonDown()
    {
        if (!base.IsUseButtonDown()) return false;
        var ray = Camera.main.ScreenPointToRay(InputDeviceManager.GetMousePosition());
        RaycastHit hit;
        var numHits = Physics.RaycastNonAlloc(ray, hits, maxSelectionDistance, layerMask);
        for (int i = 0; i < numHits; i++)
        {
            if (hits[i].collider.GetComponent<Usable>() == currentUsable)
            {
                return true;
            }
        }
        return false;
    }
}