- Home /
Question by
FullHeartGames · May 16, 2016 at 05:44 AM ·
inputupdatedoubletetris
Tetris Controls - Input calling multiple times
I am invoking functions to perform a grid like movement. Sometimes my functions are getting multiple inputs and my pieces are stuck traveling I am guessing twice the speed.
I tried using a bunch of booleans to catch this but it doesn't see to work.
Here is my code:
void TetrisInputR()
{
InvokeRepeating("TetrisMoveR", tetrisMoveSpeed * Time.deltaTime, tetrisMoveSpeed * Time.deltaTime);
}
void TetrisMoveR()
{
this.transform.position = new Vector2(this.transform.position.x + .5f, this.transform.position.y);
Debug.Log("HORZ Right");
}
void TetrisInputL()
{
InvokeRepeating("TetrisMoveL", tetrisMoveSpeed * Time.deltaTime, tetrisMoveSpeed * Time.deltaTime);
}
void TetrisMoveL()
{
this.transform.position = new Vector2(this.transform.position.x - .5f, this.transform.position.y);
Debug.Log("HORZ LEFT");
}
void Update()
{
//Tetris Horz
if (Input.GetKeyDown(KeyCode.A) && Tetris && !isLpressed)
{
isLpressed = true;
bool once = true;
{
TetrisInputL();
}
once = false;
}
if (Input.GetKeyUp(KeyCode.A) && Tetris)
{
CancelInvoke("TetrisMoveL");
isLpressed = false;
}
if (Input.GetKeyDown(KeyCode.D) && Tetris && !isRpressed)
{
isRpressed = true;
bool once = true;
{
TetrisInputR();
}
once = false;
}
if (Input.GetKeyUp(KeyCode.D) && Tetris)
{
CancelInvoke("TetrisMoveR");
isRpressed = false;
}
}
Comment