How do I solve my Match 3 Game coding error?,
I am working on a Match 3 game by following a Unity tutorial step by step on this web page: (https://www.raywenderlich.com/673-how-to-make-a-match-3-game-in-unity)
I am currently at the step where I put in lines of code that make it so that the sprites don't spawn in groups of 3 or more when the game starts. Here's what I have so far:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BoardManager : MonoBehaviour {
public static BoardManager instance;
public List<Sprite> characters = new List<Sprite>();
public GameObject tile;
public int xSize, ySize;
private GameObject[,] tiles;
public bool IsShifting { get; set; }
void Start () {
instance = GetComponent<BoardManager>();
Vector2 offset = tile.GetComponent<SpriteRenderer>().bounds.size;
CreateBoard(offset.x, offset.y);
Sprite[] previousLeft = new Sprite[ySize];
Sprite previousBelow = null;
}
private void CreateBoard (float xOffset, float yOffset) {
tiles = new GameObject[xSize, ySize];
float startX = transform.position.x;
float startY = transform.position.y;
for (int x = 0; x < xSize; x++) {
for (int y = 0; y < ySize; y++) {
GameObject newTile = Instantiate(tile, new Vector3(startX + (xOffset * x), startY + (yOffset * y), 0), tile.transform.rotation);
tiles[x, y] = newTile;
**newTile.transform.parent = transform; // 1
List<Sprite> possibleCharacters = new List<Sprite>(); // 1
possibleCharacters.AddRange(characters); // 2
possibleCharacters.Remove(previousLeft[y]); // 3
Sprite previousBelow = null;
possibleCharacters.Remove(previousBelow);
Sprite newSprite = possibleCharacters[Random.Range(0, possibleCharacters.Count)];
newTile.GetComponent<SpriteRenderer>().sprite = newSprite; // 3
previousLeft[y] = newSprite;
previousBelow = newSprite;**
}
}
}
}
I don't understand these steps:
Create a list of possible characters for this sprite.
Add all characters to the list.
Remove the characters that are on the left and below the current sprite from the list of possible characters.
I don't use C# often, so I'm not that familiar with it. I would really appreciate it if someone were to help me.
Comment