#Multi Input Interfaces

1 messages · Page 1 of 1 (latest)

plucky bronze
#

On my camera, I have this

    {
        Ray ray = camera.ScreenPointToRay(Input.mousePosition);

        if(Physics.Raycast(ray, out RaycastHit hit))
        {
            if(hit.transform.TryGetComponent(out iInteractible interactible))
            {
                if(Input.GetMouseButtonDown(0))
                {
                    interactible.Interact();
                }
            }

            if(hit.transform.TryGetComponent(out iHoverable hoverable))
            {
                hoverable.OnHover();
            }
        }
    }```

Then on an object, I have this:
```public void Interact()
    {
        light.SetActive(!light.activeInHierarchy);
    }```

Is there a way to tell if say, left click or right click was pressed, and do the appropriate action? I know how to do this without an interface, but I'm trying to make this easily scalable as I add more stuff.
#

Like, if I am looking at a door, left click to open, or right click to lock.

waxen pewter
#
if (input.getkeydown(keycode.mouse0))
{
bool isLeftMousePressed = true;
}

something like thi?

light comet
#

check the other mouse button too?

neat kraken
#

Interfaces can implement more than 1 method

waxen pewter
#
if (isLeftMousePressed)
{
OpenDoor();
}
else
{
LockDoor();
}
neat kraken
#

Interact() InteractB() and etc

plucky bronze
#

okay i feel dumb now haven't really use interfaces much before
trying to make a project that is actually made well that doesn't become garbage after a few months
thanks for the tips

light comet
#

though

#

that's just if not clicking

waxen pewter
#

you could check it on mousedown

#

then make it false on mouse up