Questions for operating with mouse only

Announcements, support questions, and discussion for the Dialogue System.
gaku2_sigehiro
Posts: 36
Joined: Sun Jul 14, 2024 2:35 am

Re: Questions for operating with mouse only

Post 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.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Questions for operating with mouse only

Post 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;
    }
}
Post Reply