How to disable joystick/keyboard from interacting with dialogs in Unity UFPS - c#

I am developing a 3D game with a custom chat console using Unity and UFPS,
https://assetstore.unity.com/packages/tools/game-toolkits/ufps-ultimate-fps-106748
Everything is working, but running on Android TV with a joystick, keyboard and mouse we want to control which input affects what.
So we want the dialog to only be able to interact with the mouse.
and the joystick to only interact with the game/player.
Original the mouse was controlling the players looking, and able to select the dialog.
I was able to disable the mouse from controlling the player by,
Unity menu, Edit, Project Settings, Input
Then finding the "Mouse X" and Mouse Y" input events and renaming the ones with the mouse input to "Mouse XX", and leaving the joystick axis events for "Mouse X" so the joystick can still control the players looking.
Now I am having the opposite issue, the joystick and the arrow keyboard keys are toggling the selection in the dialog, and the joystick button/space key trigger selection in the dialog. I want to disable this so only the mouse can interact with the dialog and the joystick on controls the player movement.
I tried changing the Input for "Horizontal" "Vertical" by renaming to "Horizontal xxx". This works, but then the joystick is also not controlling the player movement. So how can I make these separate events.
I cannot find any code listening to "Horizontal" or "Vertical" events, these seem to be hardwired in Unity some how??

If I am understanding you correctly, you want to disable all input other than a mouse click on UI elements. On the EventySystem object in your scene, select it and on the component EventSystem there is a toggle called Send Navigation Event. If you uncheck this box, it will disable all gamepad/keyboard interactions with UI and only allow mouse inputs to select UI.

Related

What tells unity that a cursor is hovering over a button and how can Unity Netcode for Gameobjects affect it?

What tells unity that a cursor is hovering over a button (how does it know when to highlight it or do something when a click happens and the cursor is on it). And how does the Unity Netcode for GameObjects affect it? I have a problem with my game that uses the Unity Netcode for GameObjects netcode and it has a problem so that when you are a connected client it doesnt register any cursor and UI interactions (when hovering over the UI element it doesn't get highlighted or when clicked it doesn't do anything)
Try checking any object below that GameObject, to not cover that button and to not have Raycast Target on.
Unity, to recognize a click or a hover, permanently calculate a raycast between World Space and your Cursor, so if it hits, and have the Raycast Target on, it will trigger on the first object it hit, ignoring others.

I want to create a setting screen in a scene using FPSController, but I can not click on the editor

Display the UI of the setting screen in the scene using the FPSController, And I want to be able to set up the game (for example, the camera's FOV).
the mouse cursor is appeared by pushed ESC key.
However, when the FPSController is active, the mouse cursor disappears when clicked and setting can not be made.
I checked the script, FirstPersonController.cs (script for FPSController gameObject), but there was no description about mouse cursor.
The FirstPersonController.cs has not been rewritten. There is a code at the link below.
https://qiita.com/ABCDEEEEEE/items/4f2452a88fb1050684fc
I want to keep the mouse cursor from disappearing even when FPSController is active.

Mouse and Cat chasing game

I have to make a Windows Form Application which has to be a cat chasing a mouse. And you move the mouse with the arrow keys while that cat is going towards the mouse. It should detect when they both get in contact and show the time it took.
Both the cat and mouse should be placed randomly in the window each new game. And in higher difficulty, it should have two holes and when the mouse goes in one of them it shows on the other. Can someone help because I have no idea where to start the main part?
I've already placed pictures if a cat and a mouse in separate picture boxes and made the part with choosing difficulty.
You'd basically be combining these steps:
Implement an OnKeyDown handler to respond to key presses. Reposition the mouse image when this occurs.
Create a timer for the cat animation. At each step move the cat towards the mouse's position.
Whenever the position of one of the objects changes, check if there's a collision and handle it appropriately.
It's pretty simple to do this with a game engine as well. That would handle the animation for you. Here's how you'd get started with Unity for example:
https://msdn.microsoft.com/en-us/magazine/dn759441.aspx

Unity2D: Panning a map using touch still register even a button in canvas is tapped

I have a problem cancelling pan feature of my app when a button in HUD is pressed.
We're using canvas for displaying UIs, so I can't use the RayCast to detect if a touch hit a button or not since the button is not directly in the world where the map to be panned located.
I already added collider to the buttons and tried printing the name of objects hitted by raycast but it just passes through the buttons like they are not there.
How am I suppose to detect if a button in canvas is touched so I can cancel executing pan feature?
Check EventSystem's IsPointerOverGameObject method. You can use it like this:
public bool IsPointerOverUI
{
get{
return EventSystem.current.IsPointerOverGameObject();
}
}
Don't forget to import UnityEngine.EventSystems

Suppress mouse-movement

I need to freeze the windows mouse cursor on the screen, so it stays hovered over a specific UI element. While the mouse is in this frozen state, I would still like to be able to interact with the UI using a "fake" mouse pointer.
Currently, I've got a low level mouse hook that prevents WM_MOUSEMOVE messages from being passed along, effectively stopping all real mouse movement. However, when I don't pass along the updated coordinates, windows actually sends me the old coordinates in a separate WM_MOUSEMOVE message, as if to correct for the fact that the mouse didn't move.
Any idea on either how to prevent Windows from sending me these corrected coordinates, or another approach of how I can freeze the actual mouse curosr and still allow the physical mouse to control a "Fake" cursor?
You can suppress mouse cursor movement by using DirectInput exclusive mode.
You should acquire mouse input device when cursor movement must be suppressed. This will block windows cursor movement but you can get messages for your fake cursor using DirectInput API.
If you move the mouse cursor position in response to a WM_MOUSEMOVE message, to put the mouse back to where you want it, you will get another mouse move message because the mouse has been moved again (because you moved it). To stop this, don't set the mouse position if it is already in the right place.
You may also want to clip the mouse position to your window and get exclusive access to it.
Why don't you just draw an image of the cursor at the place you want it frozen, then set the real mouse cursor to be hidden (Cursor.Hide IIRC).
It's not clear to me what you are trying to do, perhaps making a tutorial for your app and you want to show mouse movements, etc. Perhaps this library will be useful:
http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx

Categories

Resources