Hi,
I’m making an infinite runner as a first game that I’ll be doing without a step by step tutorial. It is based on the flash game Shift which you can find on Armor Games. The way I have decided to do the switching (where white turns to black and black turns to white) is by setting the relevant blocks to be inactive at the right time.
I have checked all over the forums and can’t find similar issues, so it may just be me. However, I’d really like help solving this problem.
The relevant code:
void Update () {
bool change = Input.GetButtonDown("Switch");
if (change == true) {
black = GameObject.FindGameObjectsWithTag("Black");
white = GameObject.FindGameObjectsWithTag("White");
blackBlocks = GameObject.FindGameObjectsWithTag("BlackBlocks");
whiteBlocks = GameObject.FindGameObjectsWithTag("WhiteBlocks");
foreach(GameObject gO in black) {
gO.gameObject.tag = "White";
gO.gameObject.GetComponent<Renderer>().material = whiteMaterial;
}
foreach(GameObject gO in white) {
gO.gameObject.tag = "Black";
gO.gameObject.GetComponent<Renderer>().material = blackMaterial;
}
foreach(GameObject gO in blackBlocks) {
if(isBlackTrue == true){
gO.gameObject.SetActive(false);
Debug.Log("blacktrue");
}
else if (isBlackTrue == false) {
gO.gameObject.SetActive(true);
}
}
foreach(GameObject gO in whiteBlocks) {
if(isWhiteTrue == true){
gO.SetActive(false);
}
else if (isWhiteTrue == false) {
gO.SetActive(true);
}
}
isBlackTrue = !isBlackTrue;
isWhiteTrue = !isWhiteTrue;
}
What this code does, is gets the blocks with the relevant tags, and switches them around. The black and white are the background, and the blackBlocks and whiteBlocks are being set inactive as they are the ones the player needs to switch to try to land on.
If you look at the debug.log on line 21, you see it should likely activate every two times the player switches, but it only activates once, and never again, suggesting to me that something is wrong with the booleans.
Any help is appreciated and, if I cannot find a solution, alternative methods of achieving the same goal are also welcome.
(Sorry if this is meant to be in scripting!)
ADESONOM