//checks through tokens[] in order, checking tags. First token found whose tag is not matching the Token Block tag is replaced with a Token Block. Returns the index that was replaced with a Block. private int spawnBlockAtLowestIndex() { int targetIndex = -1; //currently not random. Should make random? Random space on the lowest row gets a block? for (int i = 0; i < tokens.Length; i++) { GameObject token = tokens[i]; if (!(token.CompareTag(tokenBlockTag))) //if the token isn't a block, store its index and break the loop. { targetIndex = i; break; } } Vector2Int loc = ConvertIndexToLocation(targetIndex); GameObject TokenBlockInstance = Instantiate(TokenBlock, ConvertLocationToTransformVector3(loc), Quaternion.identity, canvas.transform); TokenSelectedScript tokenScript = TokenBlockInstance.GetComponent <TokenSelectedScript>(); tokenScript.gameManager = this.gameObject; tokenScript.xOnBoard = loc.x; tokenScript.yOnBoard = loc.y; Destroy(tokens[targetIndex]); tokens[targetIndex] = TokenBlockInstance; return(targetIndex); }
//creates a Token at location parameter public GameObject InstantiateRandomTokenAtLocation(Vector2Int loc) { int type = Random.Range(0, tokenTypes.Length); GameObject token = Instantiate(tokenTypes[type], ConvertLocationToTransformVector3(loc), Quaternion.identity, canvas.transform); TokenSelectedScript tokenScript = token.GetComponent <TokenSelectedScript>(); tokenScript.gameManager = this.gameObject; tokenScript.xOnBoard = loc.x; tokenScript.yOnBoard = loc.y; return(token); }
//changes internal location and adds token to move List. DOES NOT ASSIGN TOKEN TO NEW INDEX IN "tokens" public void moveTokenToIndex(GameObject token, int indexDestination) { //change internal location TokenSelectedScript tokenScript = token.GetComponent <TokenSelectedScript>(); Vector2Int loc = ConvertIndexToLocation(indexDestination); tokenScript.xOnBoard = loc.x; tokenScript.yOnBoard = loc.y; //update position //UpdateInternalPosition(indexDestination); //Instead: start token moving to destination movingTokensList.Add(token.transform); movingTokensDestinationList.Add(ConvertLocationToTransformVector3(ConvertIndexToLocation(indexDestination))); //Mark tokens as having moved since last check movedSinceLastProcessing.Add(indexDestination); }