Home unity3d Is it possible in Unity Input Manager Add Ui Button?

Is it possible in Unity Input Manager Add Ui Button?

Author

Date

Category

Is there any opportunity to add events received from UI to Unity (for example click from the button) in the standard Input Manager?


Answer 1, Authority 100%

No, you can not add events to the standard input manager .

You can write wrapper to the standard input manager which would return something that you need. (And this wrapper No one bothers inside the use of input.getaxis ) or search asset which already knows how to do it.

Although in many situations such frills are not needed, it will be enough of something like:

using system;
using unityengine;
using button = unityengine.uielements.button;
Public Class Controller: Monobehaviour
{
  [SerializeField]
  Private Button Rightbutton;
  Private Direction Direction = direction.undefined; // Field, cat. affects the overall functionality
  Private Void Start ()
  {
    rightbutton.clicked + = () = & gt; {direction = direction.right;}; // Changing the influencing variable based on UI Events
  }
  Private void Update ()
  {
    if (input.getaxis ("horizontal") & gt; 0)
    {
      Direction = Direction.Right; // Change influencing variable based on InputManager
    }
    Move (); // call a method with common functionality
  }
  Private Void Move () // Method with common functionality
  {
    Switch (DIRECTION)
    {
      Case Direction.up:
        Throw New NotimplementeDextException ();
      Case Direction.down:
        Throw New NotimplementeDextException ();
      Case Direction.left:
        Throw New NotimplementeDextException ();
      Case Direction.Right:
        Throw New NotimplementeDextException ();
      Case Direction.undefined:
        Throw New NotimplementeDextException ();
      Default:
        Throw New NotimplementeDextException ();
    }
  }
}
Public Enum Direction.
{
  Up,
  DOWN,
  Left
  Right,
  Undefined.
}

Answer 2

Digging a little, I realized that Unity developers strongly recommend everything to go to a new INPUT SYSTEM, which is available in version 1.0.1 starting with UNITY 2019.1. Installed via Package Manager:

The official documentation is here .

The new system is much more flexible, including a solution to my question. The (or other UI element) button hangs the component in which it is indicated which key it must duplicate:

Next, when you click on this onscreen button, the logic that you are prescribed for this key are not needed, nothing else is needed.

Decided to share, perhaps someone will be useful.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions