Humanoid Button

Unity provides an great UI system which includes a Button component which can call functions on objects when it is pressed. Humanoid Control supports this in different ways. A limitation is that you cannot determine who has pressed the button which can be useful in multiplayer environments. For this case we provide the Humanoid Button.

When a Humanoid Button is pressed, a function can be called which takes a HumanoidControl parameter representing the humanoid who pressed the button. This parameter can be used to make the functionality dependent on who pressed the button.

Setup

The easiest way to use the Humanoid Button is to start with a normal UI Button in the scene. This can be done by right clicking in the hierarchy and choosing UI->Button:

Now we get a standard button attached to the Canvas

At the button you can see the Unity Event which is used to call a function when the button is pressed. From the title bar of this Unity Event you can see that it can only call function without parameters On Click ().

Now we should remove the standard Button from the object using the little ‘cog wheel’ icon on the right:

After that, we add the Humanoid Button to replace the standard Button:

You’ll see that it is almost the same as the normal Button, so we can reuse everything we know about buttons. The different lies in the On Click event:

In the Humanoid Button, the On Click event has a HumanoidControl parameter. This can be used to call functions which take a HumanoidControl parameter.

For example, we can now call the TeleportToHere(HumanoidControl humanoid) function on a Teleport Target. This will have the effect that the humanoid who pressed the button will be teleported to the location of the Teleport Target.

You see that for a Teleport Target, you can now choose the Dynamic HumanoidControl-TeleportToHere. Choosing this option will teleport the humanoid who pressed the button to the location of the Teleport Target.

At the bottom you will also see the Static Parameters-TeleportToHere (HumanoidControl). With this option the humanoid who pressed the button will be ignored and you can select explicitly which humanoid will be teleported. This humanoid can thus be different from the humanoid who pressed the button.

Note, this last option is also possible with the standard Button.