Toggle an input

ぃ、小莉子 提交于 2019-12-02 08:07:19

You may use a bool to determine if the button is toggled on or off. You will also need to know the gamepad's previous state, so the bool won't toggle all the time, just because you keep pressing the button.

bool myCommand = false; // declare the bool
GamePadState oldState; // you need to know the previous state of your gamepad

public void Update()
{
    if (GamePad.GetState().KeyPressed == /*key*/ && oldState.KeyPressed != /*key*/)
        myCommand = !myCommand;
    oldState = GamePad.GetState();
}

Keep in mind, that you may need to use something other than GamePad or GamePadState, as this is merely pseudo-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!