// method which changes the player color void ChangeCubePlayerColor() {//get the tile name and convert it into number int i = int.Parse(parentTile.name); //check the direction if (direction == Vector3.right) {//if moving right then we check if the tile number is below 3 if (i < 3) {//if yes then we add 1 to it i = i + 1; //then we assign the color of next tile to the player cubePlayer.AssignColor(tileList[i].spriteColor, tileList[i].colorInd); }//if the tile is 3 which is last from the roght side else if (i == 3) {//then we randomly get the color int r = Random.Range(0, TileHolder.instance.colors.Length); cubePlayer.AssignColor(TileHolder.instance.colors[r], r); } } else if (direction == Vector3.left) {//if moving left then we check if the tile number is below 3 if (i > 0) {//if yes then we minus 1 from it i = i - 1; //then we assign the color of next tile to the player cubePlayer.AssignColor(tileList[i].spriteColor, tileList[i].colorInd); } else if (i == 0) { int r = Random.Range(0, TileHolder.instance.colors.Length); cubePlayer.AssignColor(TileHolder.instance.colors[r], r); } } //add color ind ref of the player to holder //this ensure that atlest one tile will have color matching to the player holder.cubeColorInd = cubePlayer.colorInd; }