Wednesday, August 24, 2016

Why is spacebar causing Unity to fire last OnClick() event



I have a turn based roguelike with input issues that are driving me nuts.


I use the Unity Input/GetAxis() for keyboard input. I recently added a skill bar with clickable buttons that pass an int parameter to a simple class when clicked.


The problem I am having is that the OnClick() event, on the last button that was clicked, fires whenever the SPACE bar is pressed.


What could cause this? I do not have space set on any of the input Axes (I did originally and both the axes attached to SPACE and the OnClick() would fire)


Edit: The code is below. It is called by the OnClick() handler on the button in the inspector. If you run the project and press SPACE nothing happens. Then if you click a button the Debug.Log fires. Then press SPACE again and the debug fires again with the same button number as was last clicked.


public class SkillClickNotifier : MonoBehaviour
{
[HideInInspector]
public int SkillClicked;


public void ButtonClicked(int skill)
{
Debug.Log("Button Clicked: "+ skill);
// SkillClicked = skill;
// GameManager.Notifications.PostNotification(this, "SkillClicked");
}
}


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...