#Multi Input Interfaces
1 messages · Page 1 of 1 (latest)
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.
if (input.getkeydown(keycode.mouse0))
{
bool isLeftMousePressed = true;
}
something like thi?
check the other mouse button too?
Interfaces can implement more than 1 method
if (isLeftMousePressed)
{
OpenDoor();
}
else
{
LockDoor();
}
Interact() InteractB() and etc
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
that doesn't account for rmb
though
that's just if not clicking