So ive been working on a game where the player can shift its shape when press J, K, or L key. The problem is I want to restrict the player from pressing the same key twice so i code some if statement as below:-
public GameObject sphere;
public GameObject cube;
//public GameObject pyramid;
bool keypressJ = false;
bool keypressK = true;
void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.J) && keypressJ == false)
{
sphere.transform.position = cube.transform.position;
sphere.SetActive(true);
cube.SetActive(false);
//pyramid.SetActive(false);
keypressJ = true;
keypressK = false;
Debug.Log("keypress J = " + keypressJ);
}
if (Input.GetKeyDown(KeyCode.K) && keypressK == false)
{
cube.transform.position = sphere.transform.position;
cube.SetActive(true);
sphere.SetActive(false);
//pyramid.SetActive(false);
keypressJ = false;
keypressK = true;
Debug.Log("keypress J = " + keypressJ);
}
when i run the game it run perfectly on the first shift. but after it returns to cube shape, i cant shift it back to sphere. i have look around for answer but still couldnt find any. this is my first time posting on the community so i hope my question is clear enough. any help is very much appreciated.